Solved Dynamic QProcess
I created a QProcess pointer in mainwindow.h.
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?
@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.
JonB last edited by JonB
As @wrosecrans has said, it is your responsibility to delete the
QProcesswhen you are done with it. For a simple example, if you are not interested in anything further from the
QProcessafter 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.