Call the compiled C language module, PASS Parameters, and print the returned results.
C language module code:
/********** Test. c ********** // *********** after compiling with GCC, the executable file test is produced and stored in .... */# include <stdio. h> int main (INT argc, char * argv []) {printf ("Hello, I am a C program! \ N "); printf (" now, I am invoked by a program called QT! \ Nfollowing are the parameters that QT sends to me: \ n "); printf (" % s \ n ", argv [0]); printf (" % s \ n ", argv [1]); printf ("% s \ n", argv [2]); Return 0 ;}
Qt code:
/********MyTest.h***********/#ifndef MYTEST_H_#define MYTEST_H_#include <QtGui/QWidget>#include <QtGui/QPushButton>class MyTest : public QWidget{ Q_OBJECT public: MyTest(); ~MyTest(); public slots: void invokeC(); private: QPushButton *pb;};#endif
/******* Mytest. CPP **********/# include "mytest. H "# include <qtcore/qprocess> # include <iostream> # include <qtcore/qtextstream> # include <qtcore/qiodevice> mytest: mytest (): qwidget () {This-> setgeometry (, 50); Pb = new qpushbutton ("click to call C program", this); Pb-> setgeometry (, 50); Connect (Pb, signal (clicked (), this, slot (invokec ();} mytest ::~ Mytest () {} void mytest: invokec () {qprocess * process = new qprocess (); qstringlist STR; Str. clear (); STR <"A" <"B"; process-> Start (".. /C/test ", STR); process-> waitforstarted (); process-> waitforfinished (); qbytearray QB = process-> readall (); qstring str22 (QB ); qtextstream cout (stdout); cout <str22 <Endl ;}
/*********** Main. CPP ************ // ********* after compilation, put it in ..... */# include <qtgui/qapplication> # include <qtcore/qtextcodec> # include "mytest. H "int main (INT argc, char * argv []) {qapplication A (argc, argv); qtextcodec * codec = qtextcodec: codecforlocale (); qtextcodec :: setcodecforcstrings (codec);. setfont (qapplication: font (); mytest * Mt = new mytest; MT-> show (); Return a.exe C ();}
Running result:
(-------- End --------)