Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Problem in QProcess
Forum Updated to NodeBB v4.3 + New Features

[Solved] Problem in QProcess

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Paawan
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      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;@

      157

      1 Reply Last reply
      0
      • P Offline
        P Offline
        Paawan
        wrote on last edited by
        #3

        Thank you very much it works.

        Where can I read a bit more on the difference between creating on the stack and heap?

        1 Reply Last reply
        0
        • p3c0P Offline
          p3c0P Offline
          p3c0
          Moderators
          wrote on last edited by
          #4

          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

          157

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved