In QT programming, it is sometimes necessary to call an already written program to process the data in the program being written.
The process needs to be used to invoke the already written program.
Write the good one layout program beforehand:
#include <QApplication> #include <QPushButton> #include <QGridLayout> #include <qlabel># Include<qlineedit> #include <qmainwindow>int main (int argc, char *argv[]) {qapplication app (argc, argv); Qwidget *window = new Qwidget; Qgridlayout *vlayout = new qgridlayout (window); Qlabel *label1 = new Qlabel ("Query", window); Vlayout->addwidget (label1,0,0); Qlineedit *edit1 = new qlineedit (window); Vlayout->addwidget (edit1,0,1); Qpushbutton *button1 = new Qpushbutton ("Query", window); Vlayout->addwidget (button1,0,2); Qlabel *label2 = new Qlabel ("Answer", window); Vlayout->addwidget (label2,1,0); Qlineedit *edit2 = new qlineedit (window); Vlayout->addwidget (edit2,1,1); Qpushbutton *button2 = new Qpushbutton ("Clear", window); Vlayout->addwidget (button2,1,2); Window->setlayout (vlayout); Window->show (); return app.exec ();}
Put it under the Layout folder
Qmake-project
Qmake
Make
Get the layout executable file
You can invoke the Lauot program by adding the following code when you write another program:
QString program = ". /layout/layout ";//Specifies the path of the executable program to invoke qprocess *myprocess = new Qprocess (this); This means that Myprocess's parent window is the main window in this program, and when the main window is closed, the process terminates,//If the this,myprocess is independent, the main window is closed and the process is still running Myprocess->start ( program);
If the program has parameters, it is written in the following form:
QString program = ". /layout/layout "; Qstringlist arguments; Arguments << "*" << "*"; Add parameter qprocess *myprocess = new Qprocess (this); Myprocess->start (program, arguments);
Reference: QT Help documentation
Use of QT process programming: Calling another program in one program