In Qt Creator on Windows, qDebug() statements don't work, and the following message appears in the output window:
Cannot retrieve debugging output.
How can it be fixed?
Or you may be running a version of DebugView from Sysinternals, that causes the same result.
Well, I had two instances of QtCreator and I could not close one of them. They work together.
One workaround for this problem is redirecting your application output messages using qInstallMessageHandler.
#include "mainwindow.h"
#include <QApplication>
void redirectedOutput(QtMsgType, const QMessageLogContext &, const QString &);
QMutex debugOutMutex;
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
qInstallMessageHandler(redirectedOutput);
MainWindow w;
w.show();
return app.exec();
}
void redirectedOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
debugOutMutex.lock();
std::cout << QDateTime::currentDateTime().toString("hh.mm.ss.zzz ").toStdString() << msg.toStdString() << std::endl;
if (type == QtFatalMsg) {
abort();
}
debugOutMutex.unlock();
}
I added a QMutex too. If your application is utilizing more than one thread, debug outputs can be mixed.