summaryrefslogtreecommitdiffstats
path: root/examples/process/process.cpp
blob: 5c3c73c9849b99f782c2ce942a737be5cfad4200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/****************************************************************************
**
** Copyright (C) 1992-2008 Trolltech ASA.  All rights reserved.
**
** This file is part of an example program for TQt.  This example
** program may be used, distributed and modified without limitation.
**
*****************************************************************************/

#include <ntqobject.h>
#include <ntqprocess.h>
#include <ntqvbox.h>
#include <ntqtextview.h>
#include <ntqpushbutton.h>
#include <ntqapplication.h>
#include <ntqmessagebox.h>

#include <stdlib.h>

class UicManager : public TQVBox
{
    TQ_OBJECT

public:
    UicManager();
    ~UicManager() {}

public slots:
    void readFromStdout();
    void scrollToTop();

private:
    TQProcess *proc;
    TQTextView *output;
    TQPushButton *quitButton;
};

UicManager::UicManager()
{
    // Layout
    output = new TQTextView( this );
    quitButton = new TQPushButton( tr("Quit"), this );
    connect( quitButton, TQ_SIGNAL(clicked()),
	    tqApp, TQ_SLOT(quit()) );
    resize( 500, 500 );

    // TQProcess related code
    proc = new TQProcess( this );

    // Set up the command and arguments.
    // On the command line you would do:
    //   uic -tr i18n "small_dialog.ui"
    proc->addArgument( "uic" );
    proc->addArgument( "-tr" );
    proc->addArgument( "i18n" );
    proc->addArgument( "small_dialog.ui" );

    connect( proc, TQ_SIGNAL(readyReadStdout()),
	    this, TQ_SLOT(readFromStdout()) );
    connect( proc, TQ_SIGNAL(processExited()),
	    this, TQ_SLOT(scrollToTop()) );

    if ( !proc->start() ) {
	// error handling
	TQMessageBox::critical( 0,
		tr("Fatal error"),
		tr("Could not start the uic command."),
		tr("Quit") );
	exit( -1 );
    }
}

void UicManager::readFromStdout()
{
    // Read and process the data.
    // Bear in mind that the data might be output in chunks.
    output->append( proc->readStdout() );
}

void UicManager::scrollToTop()
{
    output->setContentsPos( 0, 0 );
}

int main( int argc, char **argv )
{
    TQApplication a( argc, argv );
    UicManager manager;
    a.setMainWidget( &manager );
    manager.show();
    return a.exec();
}

#include "process.moc"