[Solved] Problem in QProcess
I am beginner in QT. I am making an application that uses QProcess to call another program. But for some reason it is not working.
A2Q2::A2Q2(QWidget *parent) :
QGridLayout * layout = new QGridLayout(this); this->setLayout(layout); QPushButton * but1 = new QPushButton("Click to Add"); layout->addWidget(but1); connect (but1,SIGNAL(clicked()),this,SLOT (startQ1())); ui->setupUi(this);
QProcess process; process.start("C:/Qt/Qt5.0.2/Tools/QtCreator/bin/build-Ass2Q1-Desktop_Qt_5_0_2_MSVC2012_64bit-Debug/debug/Ass2Q1.exe");
The window opens with a button but when I click on the button nothing happens.
Since you have creates the QProcess object on stack the QProcess's object gets deleted as soon as the function exits.
You should create the QProcess object on the heap instead on the stack.
@QProcess *process = new QProcess;@
Thank you very much it works.
Where can I read a bit more on the difference between creating on the stack and heap?
Your welcome :)
There are lots of study materials regarding it. Just google it.
Anyway here are some links.