[Solved] Problem in QProcess
-
Hi,
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.
@
#include <QPushButton>
#include <QProcess>A2Q2::A2Q2(QWidget *parent) :
QWidget(parent),
ui(new Ui::A2Q2)
{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);
}
void A2Q2::startQ1(){
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.
Please help.
Thanks
-
Hi,
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.
So
@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.http://www.learncpp.com/cpp-tutorial/79-the-stack-and-the-heap/
http://programmingexamples.wikidot.com/stack-vs-heap