Important: Please read the Qt Code of Conduct -

[SOLVED] program crash when restart a process

  • 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);

    As you can see, i just trying the code wich is provided by the class explanation on

    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,

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

  • 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)

  • 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)

  • 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);

    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?

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

  • Ok,
    thank you both very much!!

Log in to reply