从 QMainWindow 启动的 QProcess 冻结 window

QProcess started from a QMainWindow freezes window

我有一个简单的QMainWindow,用户可以在其中设置一些参数。 我有三个按钮,单击它们会创建一个显示 QMainWindow 的新 QProcess。例如,main window 的按钮 A 启动 QProcess A,main window 的按钮 B 启动进程 B,等等。 我希望能够与主 window 交互,因为现在当我单击按钮时 QProcess 正确启动,显示另一个 window 等,但原始主 window 保持 冻结 直到 QProcess 结束。

有没有办法保持主要 window 响应,以便可以与其交互 WHILE QProcess/QProcesses runs/run?

编辑: 下面是我启动进程的方式:

QProcess process;
process.execute("../../RRTStar/RRTStar", QStringList() << "--file" << "../../settings.conf");

其中 RRTStar 是可执行文件的名称,--file ../../settings.conf 是命令行参数。请注意,RRTStar 由一个 MainWindow 组成,并使用线程运行大量计算。

来自官方文档的信息:

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

如果要进行异步non-blocking调用,需要使用QProcess::start():

void QProcess::start(const QString & program, const QStringList & arguments, OpenMode mode = ReadWrite)

关于一个与进程的交互:它继承了QIODevice,所以

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