source: trunk/examples/process/process.cpp

Last change on this file was 48, checked in by dmik, 20 years ago

Imported examples/process and examples/sound from the official release 3.3.1 from Trolltech.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1/****************************************************************************
2** $Id: process.cpp 48 2006-01-08 15:39:36Z dmik $
3**
4** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
5**
6** This file is part of an example program for Qt. This example
7** program may be used, distributed and modified without limitation.
8**
9*****************************************************************************/
10
11#include <qobject.h>
12#include <qprocess.h>
13#include <qvbox.h>
14#include <qtextview.h>
15#include <qpushbutton.h>
16#include <qapplication.h>
17#include <qmessagebox.h>
18
19#include <stdlib.h>
20
21class UicManager : public QVBox
22{
23 Q_OBJECT
24
25public:
26 UicManager();
27 ~UicManager() {}
28
29public slots:
30 void readFromStdout();
31 void scrollToTop();
32
33private:
34 QProcess *proc;
35 QTextView *output;
36 QPushButton *quitButton;
37};
38
39UicManager::UicManager()
40{
41 // Layout
42 output = new QTextView( this );
43 quitButton = new QPushButton( tr("Quit"), this );
44 connect( quitButton, SIGNAL(clicked()),
45 qApp, SLOT(quit()) );
46 resize( 500, 500 );
47
48 // QProcess related code
49 proc = new QProcess( this );
50
51 // Set up the command and arguments.
52 // On the command line you would do:
53 // uic -tr i18n "small_dialog.ui"
54 proc->addArgument( "uic" );
55 proc->addArgument( "-tr" );
56 proc->addArgument( "i18n" );
57 proc->addArgument( "small_dialog.ui" );
58
59 connect( proc, SIGNAL(readyReadStdout()),
60 this, SLOT(readFromStdout()) );
61 connect( proc, SIGNAL(processExited()),
62 this, SLOT(scrollToTop()) );
63
64 if ( !proc->start() ) {
65 // error handling
66 QMessageBox::critical( 0,
67 tr("Fatal error"),
68 tr("Could not start the uic command."),
69 tr("Quit") );
70 exit( -1 );
71 }
72}
73
74void UicManager::readFromStdout()
75{
76 // Read and process the data.
77 // Bear in mind that the data might be output in chunks.
78 output->append( proc->readStdout() );
79}
80
81void UicManager::scrollToTop()
82{
83 output->setContentsPos( 0, 0 );
84}
85
86int main( int argc, char **argv )
87{
88 QApplication a( argc, argv );
89 UicManager manager;
90 a.setMainWidget( &manager );
91 manager.show();
92 return a.exec();
93}
94
95#include "process.moc"
Note: See TracBrowser for help on using the repository browser.