Important: Please read the Qt Code of Conduct -

[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) :
    ui(new Ui::A2Q2)

    QGridLayout * layout = new QGridLayout(this);
    QPushButton * but1 = new QPushButton("Click to Add");
    connect (but1,SIGNAL(clicked()),this,SLOT (startQ1()));


    void A2Q2::startQ1(){

    QProcess process;


    The window opens with a button but when I click on the button nothing happens.

    Please help.


  • Moderators

    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?

  • Moderators

    Your welcome :)
    There are lots of study materials regarding it. Just google it.
    Anyway here are some links.

Log in to reply