diff options
Diffstat (limited to 'examples/process/process.cpp')
-rw-r--r-- | examples/process/process.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/examples/process/process.cpp b/examples/process/process.cpp new file mode 100644 index 000000000..32368dc57 --- /dev/null +++ b/examples/process/process.cpp @@ -0,0 +1,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 <qobject.h> +#include <qprocess.h> +#include <qvbox.h> +#include <qtextview.h> +#include <qpushbutton.h> +#include <qapplication.h> +#include <qmessagebox.h> + +#include <stdlib.h> + +class UicManager : public TQVBox +{ + Q_OBJECT + +public: + UicManager(); + ~UicManager() {} + +public slots: + void readFromStdout(); + void scrollToTop(); + +private: + TQProcess *proc; + TQTextView *output; + TQPushButton *tquitButton; +}; + +UicManager::UicManager() +{ + // Layout + output = new TQTextView( this ); + tquitButton = new TQPushButton( tr("Quit"), this ); + connect( tquitButton, SIGNAL(clicked()), + qApp, SLOT(tquit()) ); + 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, SIGNAL(readyReadStdout()), + this, SLOT(readFromStdout()) ); + connect( proc, SIGNAL(processExited()), + this, 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" |