ApplicationLaucher: Catch late WinDebug messages

Catch and display messages received from WinDebug interface, even
for a short while after the process has already finished.
This can apparently happen, e.g. when doing a qDebug right before
the application ends (and QT_LOGGING_TO_CONSOLE is not 1, the
application is being run in GUI mode, on windows).

Task-number: QTCREATORBUG-15546
Change-Id: I37a015da89fc409234adeb597171fa328f50c14d
Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2016-02-17 16:31:20 +01:00
parent 049675077a
commit a286c8da44
2 changed files with 18 additions and 5 deletions

View File

@@ -43,6 +43,7 @@
#include <utils/qtcprocess.h>
#include <QTextCodec>
#include <QTimer>
#ifdef Q_OS_WIN
#include <windows.h>
@@ -80,7 +81,9 @@ struct ApplicationLauncherPrivate {
QTextCodec::ConverterState m_outputCodecState;
QTextCodec::ConverterState m_errorCodecState;
// Keep track whether we need to emit a finished signal
bool m_processRunning;
bool m_processRunning = false;
qint64 m_listeningPid = 0;
};
ApplicationLauncherPrivate::ApplicationLauncherPrivate() :
@@ -114,7 +117,7 @@ ApplicationLauncher::ApplicationLauncher(QObject *parent)
d->m_consoleProcess.setSettings(Core::ICore::settings());
#endif
connect(&d->m_consoleProcess, SIGNAL(processStarted()),
this, SIGNAL(processStarted()));
this, SLOT(handleProcessStarted()));
connect(&d->m_consoleProcess, SIGNAL(processError(QString)),
this, SLOT(consoleProcessError(QString)));
connect(&d->m_consoleProcess, SIGNAL(processStopped(int,QProcess::ExitStatus)),
@@ -288,19 +291,22 @@ void ApplicationLauncher::cannotRetrieveDebugOutput()
void ApplicationLauncher::checkDebugOutput(qint64 pid, const QString &message)
{
if (applicationPID() == pid)
if (d->m_listeningPid == pid)
emit appendMessage(message, Utils::DebugFormat);
}
void ApplicationLauncher::processDone(int exitCode, QProcess::ExitStatus status)
{
emit processExited(exitCode, status);
QTimer::singleShot(100, this, [this, exitCode, status]() {
d->m_listeningPid = 0;
emit processExited(exitCode, status);
});
}
void ApplicationLauncher::bringToForeground()
{
emit bringToForegroundRequested(applicationPID());
emit processStarted();
handleProcessStarted();
}
QString ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput()
@@ -308,4 +314,10 @@ QString ApplicationLauncher::msgWinCannotRetrieveDebuggingOutput()
return tr("Cannot retrieve debugging output.") + QLatin1Char('\n');
}
void ApplicationLauncher::handleProcessStarted()
{
d->m_listeningPid = applicationPID();
emit processStarted();
}
} // namespace ProjectExplorer

View File

@@ -81,6 +81,7 @@ signals:
void error(QProcess::ProcessError error);
private slots:
void handleProcessStarted();
void guiProcessError();
void consoleProcessError(const QString &error);
void readStandardOutput();