[SOLVED] No output from qDebug(" why not.....");



  • I do not get any output from qDebug(" whatever is written here"); but qWarning(" some other text"); work as expected and show output in " Application Output " and MessageHandler if installed.
    How can I "debug" or solve this problem.
    ( Fedora 22 Xfce Qt5.4.2 & Qt5.5.0 rc)

    // wincc



  • You call the constructor of qDebug with the message you want show, but as stated by the doc (http://doc.qt.io/qt-5/qdebug.html#QDebug-2) this is not sending output to debug out.
    Use qDebug() << "whatever is written here";



  • Tried qDebug() << "whatever is written here"; No difference... no output to " Application Output " -- with qWarning all is OK

    //wincc



  • Do you have "DEFINES += QT_NO_DEBUG_OUTPUT" in your pro file. This command disables the qDebug() output.



  • @CKurdu
    No I do not have "DEFINES += QT_NO_DEBUG_OUTPUT" in my pro file, qDebug() does not work in any project new,old or any of the included example projects



  • @wincc said:

    and MessageHandler if installed.

    Can I see that code??
    Have you installed Qt using installer or building from sources??



  • @mcosta
    I have installed Qt using installer .

    // header
    #ifndef MESSAGEOUTPUT_H
    #define MESSAGEOUTPUT_H

    #include <QMainWindow>
    #include <QObject>

    class MessageOutput : public QMainWindow
    {
    Q_OBJECT
    public:
    explicit MessageOutput(QWidget *parent = 0);

    signals:

    public slots:
    };

    #endif // MESSAGEOUTPUT_H

    //source
    #include "messageoutput.h"
    #include <QFile>
    #include <QTextStream>
    #include <QDateTime>

    #define MY_ASSERT(c) if (c == false){} ;
    #define MY_ASSERT_X(c, where, what) if (c == false) ;

    void myMessageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
    {
    Q_UNUSED(context);
    QString name = "/home/wincc/myApplication.log";
    QFile file(name);

    MY_ASSERT(file.open(QIODevice::Append | QIODevice::Text));
    
    QTextStream out(&file);
    out << QDate::currentDate().toString("yyyy-MM-dd ");
    out << QTime::currentTime().toString("hh:mm:ss.zzz ");
    
    switch (type)
    {
    case QtDebugMsg:	out << "DBG"; break;
    case QtWarningMsg:  out << "WRN"; break;
    case QtCriticalMsg: out << "CRT"; break;
    case QtFatalMsg:    out << "FTL"; break;
    //case QtInfoMsg:     out << "INF"; break;
    }
    QString end = "Closing application";
    if(end == msg)
    {
        QString t = msg.leftJustified(60, ' ');
        out << " Finder " << t << "        <  " << context.function << "     " << context.line << "  >"  <<'\n';
        out << '\n';
        out.flush();
    }
    else
    {
        QString t = msg.leftJustified(60, ' ');
        out << " Finder " << t << "        <  " << context.function << "     " << context.line << "  >"  <<'\n';
        out.flush();
    }
    

    }

    MessageOutput::MessageOutput(QWidget *parent) : QMainWindow(parent)
    {
    qInstallMessageHandler(myMessageOutput);

    }

    //usage

    MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    .......
    MessageOutput(); // Starting logging to file.
    .....
    }

    //wincc



  • Hi,

    to double check I just created a simple application

    #include <QCoreApplication>
    #include <QtDebug>
    
    int main(int argc, char *argv[])
    {
        QCoreApplication app(argc, argv);
    
        qDebug() << "DEBUG";
        qWarning() << "WARNING";
    
        return 0;
    }
    

    it runs in Windows and prints

    DEBUG
    WARNING
    


  • Hi, I've had the same problem after upgrading to Fedora 22.
    After some trouble, I found out what causes this problem: a changed configuration file. Look in this post for the solution: https://forum.qt.io/topic/54820/solved-qt-qdebug-not-working-with-qconsoleapplication-or-qapplication/5

    Marius

    Edit: Fixed link - p3c0



  • The link is broken, could you fix??



  • @Marius_Linux
    Thank you, I created ~/.config/QtProject/qtlogging.ini and now it´s working.
    //wincc



  • Fedora 22 user here, never thought the distro would hinder the debugging process, it sent me on a wild chase.

    Thank you!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.