Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/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:
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
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?
andre last edited by
Does this happen with all programs, or just with Rhythmbox? What platform are you on?
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)
goetz last edited by
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)
thanks for your help, but i still got a question:
//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?
andre last edited by
If you use this (or another valid QObject) as the parent argument, QObject will take care of that automatically.
thank you both very much!!