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] program crash when restart a process
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] program crash when restart a process

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 4.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.
  • V Offline
    V Offline
    vinb
    wrote on last edited by
    #1

    i'm sorry if i start a topic wich is allready on this forum, but i couldn't find it.

    I have a problem when i try to restart the program that's already started from my program.

    this is my simple code:
    @void proefproc::on_pushButton_clicked()
    {
    QObject *parent;
    QString program = "/usr/bin/rhythmbox";
    QStringList arguments; //not used

    QProcess *myprocess = new QProcess(parent);
    myprocess->start(program);
    

    }@
    As you can see, i just trying the code wich is provided by the class explanation on
    http://doc.qt.nokia.com/4.7/qprocess.html.

    1.The first time i click the button, rythmbox starts without a problem.
    2.Then i close rythmbox.
    3. Then i press the button for a second time and the program crashed.

    I get this output:
    @Starting 'path to'/prob...
    The program has unexpectedly finished.
    'path to'/prob exited with code 0@

    As you can see, i don't get an error, but it stops unexpectedly.

    Does somebody knows, why this is hapening?

    kind regards,
    vinb

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Does this happen with all programs, or just with Rhythmbox? What platform are you on?

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vinb
        wrote on last edited by
        #3

        Hi Andre,

        It happens with every 'windowd' program i try. I didn't tried a console program, because thats not neccesary for what i want.
        I'm working on a linux machine. (ubuntu)

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          parent is an uninitialized pointer. It contains any arbitrary value, but does not point to a QObject. Either call QProcess' constructor with "this" as parent or with "0" as parent (but, in the latter case, do not forget to delete the object when you're done with it, otherwise you will have a memory leak)

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vinb
            wrote on last edited by
            #5

            Hi Volker,

            thanks for your help, but i still got a question:

            @void proefproc::on_pushButton_clicked()
            {

            //QObject *parent;
            QString program = "/usr/bin/rhythmbox";
            QStringList arguments; //not used
            
            QProcess *myprocess = new QProcess(this);
            myprocess->start(program);
            

            }@
            i don't use the qobject parent, as you suggested
            and this works!!

            But you told me to delete the process.
            what is the place i would do that?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              If you use this (or another valid QObject) as the parent argument, QObject will take care of that automatically.

              1 Reply Last reply
              0
              • V Offline
                V Offline
                vinb
                wrote on last edited by
                #7

                Ok,
                thank you both very much!!

                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