[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);
    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.

    1. 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



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



  • 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
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.