QtcProcess: Add a warning when starting a process in non-QThread

When a QProcess is being started in a thread that doesn't have
event dispatcher installed, e.g. in a thread started with
std::async(), the process signals are emitted only from inside
QProcess::waitFor...() functions, but not emitted spontaneously.
This may cause issues when adding the running process into the
ProcessReaper, as the implementation of the latter relies on
signal emission and doesn't use blocking API of QProcess.

Currently there is one case like this: ProcessCreator::createProcess()
of clangsupport library.

Change-Id: I823a139b356f62fee9e0e5d6fc8326301c36b449
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
Jarek Kobus
2022-04-27 18:57:02 +02:00
parent b971c27312
commit 703dbd9c79

View File

@@ -367,6 +367,9 @@ private:
void doDefaultStart(const QString &program, const QStringList &arguments) final void doDefaultStart(const QString &program, const QStringList &arguments) final
{ {
QTC_ASSERT(QThread::currentThread()->eventDispatcher(),
qWarning("QtcProcess::start(): Starting a process in a non QThread thread "
"may cause infinite hang when destroying the running process."));
ProcessStartHandler *handler = m_process->processStartHandler(); ProcessStartHandler *handler = m_process->processStartHandler();
handler->setProcessMode(m_setup.m_processMode); handler->setProcessMode(m_setup.m_processMode);
handler->setWriteData(m_setup.m_writeData); handler->setWriteData(m_setup.m_writeData);