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. Dynamic QProcess

Dynamic QProcess

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 327 Views
  • 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.
  • C Offline
    C Offline
    Creatorczyk
    wrote on last edited by
    #1

    Hi,

    I created a QProcess pointer in mainwindow.h.

    QProcess *process;
    

    On the GUI, I have one button that starts the process when pressed.

    process = new QProcess();
    process->start(path);
    

    If I create new objects by pressing a button again, will it be safe or will there be a memory leak?

    W JonBJ 2 Replies Last reply
    0
    • C Creatorczyk

      Hi,

      I created a QProcess pointer in mainwindow.h.

      QProcess *process;
      

      On the GUI, I have one button that starts the process when pressed.

      process = new QProcess();
      process->start(path);
      

      If I create new objects by pressing a button again, will it be safe or will there be a memory leak?

      W Offline
      W Offline
      wrosecrans
      wrote on last edited by
      #2

      @Creatorczyk If you create something with "new" and there is never a corresponding delete, then there will absolutely be a memory leak and nothing will ever destruct the QProcess object and free up the memory it used.

      1 Reply Last reply
      4
      • C Creatorczyk

        Hi,

        I created a QProcess pointer in mainwindow.h.

        QProcess *process;
        

        On the GUI, I have one button that starts the process when pressed.

        process = new QProcess();
        process->start(path);
        

        If I create new objects by pressing a button again, will it be safe or will there be a memory leak?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @Creatorczyk
        As @wrosecrans has said, it is your responsibility to delete the QProcess when you are done with it. For a simple example, if you are not interested in anything further from the QProcess after it has finished, you might do something like

        connect(process, QOverload<int, QProcess::ExitStatus>::of(&QProcess::finished),
                process, &QObject::deleteLater);
        

        In practice you should also deal with QProcess::errorOccurred() similarly. The sample just illustrates the kind of thing you should do.

        1 Reply Last reply
        2

        • Login

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