diff --git a/src/libs/utils/processreaper.cpp b/src/libs/utils/processreaper.cpp index c6d2a071f50..cbdf29abe72 100644 --- a/src/libs/utils/processreaper.cpp +++ b/src/libs/utils/processreaper.cpp @@ -31,6 +31,13 @@ #include #include +#ifdef Q_OS_WIN +#ifdef QTCREATOR_PCH_H +#define CALLBACK WINAPI +#endif +#include +#endif + using namespace Utils; namespace Utils { @@ -83,6 +90,26 @@ bool Reaper::isFinished() const return !m_process; } +#ifdef Q_OS_WIN +static BOOL sendMessage(UINT message, HWND hwnd, LPARAM lParam) +{ + DWORD dwProcessID; + GetWindowThreadProcessId(hwnd, &dwProcessID); + if ((DWORD)lParam == dwProcessID) { + SendNotifyMessage(hwnd, message, 0, 0); + return FALSE; + } + return TRUE; +} + +BOOL CALLBACK sendShutDownMessageToAllWindowsOfProcess_enumWnd(HWND hwnd, LPARAM lParam) +{ + static UINT uiShutDownMessage = RegisterWindowMessage(L"qtcctrlcstub_shutdown"); + return sendMessage(uiShutDownMessage, hwnd, lParam); +} + +#endif + void Reaper::nextIteration() { QProcess::ProcessState state = m_process ? m_process->state() : QProcess::NotRunning; @@ -96,10 +123,15 @@ void Reaper::nextIteration() if (m_lastState == QProcess::Starting) m_process->kill(); } else if (state == QProcess::Running) { - if (m_lastState == QProcess::Running) + if (m_lastState == QProcess::Running) { m_process->kill(); - else + } else if (m_process->program().endsWith(QLatin1String("qtcreator_ctrlc_stub.exe"))) { +#ifdef Q_OS_WIN + EnumWindows(sendShutDownMessageToAllWindowsOfProcess_enumWnd, m_process->processId()); +#endif + } else { m_process->terminate(); + } } m_lastState = state; @@ -149,10 +181,7 @@ void ProcessReaper::reap(QProcess *process, int timeoutMs) if (process->state() == QProcess::NotRunning) { process->deleteLater(); return; - } else { - process->kill(); } - // Neither can move object with a parent into a different thread // nor reaping the process with a parent makes any sense. process->setParent(nullptr); diff --git a/src/tools/processlauncher/processlauncher.qbs b/src/tools/processlauncher/processlauncher.qbs index b2fd708169c..7951acee037 100644 --- a/src/tools/processlauncher/processlauncher.qbs +++ b/src/tools/processlauncher/processlauncher.qbs @@ -8,6 +8,9 @@ QtcTool { cpp.defines: base.concat("QTCREATOR_UTILS_STATIC_LIB") cpp.includePaths: base.concat(pathToUtils) + cpp.dynamicLibraries: [ + "user32", + ] files: [ "launcherlogging.cpp",