I have a simple QMainWindow
in which user can set some parameters.
I have three buttons which, when clicked, create a new QProcess
displaying a QMainWindow
. For example, main window's button A
starts QProcess A
, main window's button B
starts process B
, etc.
I'd like to be able to interact with the main window, because now when I click the button the QProcess
starts correctly, displaying another window etc, but the original main window stays frozen until the QProcess
ends.
Is there a way to maintain the main window responsive, in order to be possible to interact with it WHILE the QProcess/QProcesses runs/run?
EDIT: here's how I start processes:
QProcess process;
process.execute("../../RRTStar/RRTStar", QStringList() << "--file" << "../../settings.conf");
where RRTStar
is the name of the executable and --file ../../settings.conf
are the command line parameters. Note that RRTStar is composed of a MainWindow and runs heavy computation using threads.
Information from the official documentation:
int QProcess::execute(const QString & program, const QStringList & arguments)
Starts the program program with the arguments arguments in a new process, waits for it to finish
If you want to make asynchronous non-blocking call, you need to use QProcess::start():
void QProcess::start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite)
About an interaction with the process: it inherites QIODevice, so
QProcess allows you to treat a process as a sequential I/O device. You can write to and read from the process just as you would access a network connection using QTcpSocket. You can then write to the process's standard input by calling write(), and read the standard output by calling read(), readLine(), and getChar(). Because it inherits QIODevice...
process.write("Qt rocks!");
//...
QByteArray result = process.readAll();