jwm
jwm

Reputation: 5030

Make the debug message show up in a pop-up window rather than in QtCreator panel

I want to see the debug message show up in a pop-up window, e.g., cmd window, rather than in Qt Creator panel, specially in its Application Output. I have put CONFIG += console. but it only gives an empty window. For demonstration, here below is a simple cpp file generating debug message:

#include "mytimer.h"

myTimer::myTimer(QObject *parent) : QThread(parent)
{
    moveToThread(this);

    QTimer timer;
    timer.setInterval(1000);
    timer.start();


    connect(&timer,SIGNAL(timeout()),this,SLOT(timerHandler()), Qt::DirectConnection);
    exec();

    timer.stop();
}

void myTimer::timerHandler()
{
    qDebug()<<"timerHandler called"; //here is a debug message
}

myTimer::~myTimer()
{
    quit();
    wait();
}

Here next is for the .pro file

QT       += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = Timer
TEMPLATE = app

CONFIG += console

SOURCES += \
        main.cpp \
        mainwindow.cpp \
    mytimer.cpp

HEADERS += \
        mainwindow.h \
    mytimer.h

FORMS += \
        mainwindow.ui

Upvotes: 0

Views: 626

Answers (2)

transistor
transistor

Reputation: 669

You can specify „run in terminal“ in the project run settings. Then the debug output will be shown in a own text window, even if you have a gui application. See „Specifying Run Settings for Desktop Device Types“ in manual

Upvotes: 0

mzimmers
mzimmers

Reputation: 902

You say "pop-up" window, but then you mention the cmd window, so I'm not sure exactly what you want.

If you want to redirect the error message to a terminal window, check the "Run in terminal" box in your run settings. You may also have to use cout instead of qDebug().

If you want a true pop-up window, you'll need to create a widget. I'd recommend QMessageBox, as it's fairly easy to use.

QMessageBox *qmb;
qmb = new QMessageBox(QMessageBox::NoIcon,
                title,
                text,
                QMessageBox::Ok,
                this);
qmb->exec();
delete qmb;

Hard to say why you're not seeing any output - it could be the OS, or it might be something blocking in your app (though I'm guessing not). You could always try a good old fflush(stdout); after your qDebug() call.

Upvotes: 2

Related Questions