Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9225099
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:29:42+00:00 2026-06-18T04:29:42+00:00

After searching around for a reason that qDebug() statements work fine with Qt’s standard

  • 0

After searching around for a reason that qDebug() statements work fine with Qt’s standard message handler but fail when I switch to my own, I’m appealing here to see if anyone else has any experience with the problem.

Things I know about / have tried, that do nothing…

1) CONFIG += console

2) DEFINES -= QT_NO_WARNING_OUTPUT QT_NO_DEBUG_OUTPUT

3) ::fprintf(stderr, "ERROR\n"); ::fflush(stderr);

4) ::fprintf(stdout, "OUTPUT\n"); ::fflush(stdout);

5) std::cerr << "CERROR" << std::endl; std::cerr.flush();

However it works correctly when using the built in handler (ie it prints the message to the QtCreator console)

int main(int argc, char *argv[]) {
    // Use my handler
    qInstallMessageHandler(MyCustomLogger);
    qDebug() << "Not Printed";

    // Use standard handler
    qInstallMessageHandler(0);
    qDebug() << "Correctly Printed";

    // Use my handler again
    qInstallMessageHandler(MyCustomLogger);
    qDebug() << "Not Printed Again...";
}

The most recent test was allocating myself a console using WinAPI commands this results in the correct behavior all output to stderr and stdout are visible on the console I created. However, this is not the behavior I want, I want to be able to view this output in QtCreator.

Any thoughts on how the standard message handler prints to the debugger?
I’ve not managed to find it in the Qt sources yet.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:29:43+00:00Added an answer on June 18, 2026 at 4:29 am

    As Frank Osterfeld mentioned in his comment:

    On windows, qDebug() uses the debug channel, not stderr.

    After delving into the QDebug code and QMessageLogger I’ve found my answer. The handy WinAPI function OutputDebugString.

    Usage (Modified from peppe’s):

    #include <QApplication>
    #include <QtDebug>
    #include <QtGlobal>
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <Windows.h>
    
    void MyMessageOutput(QtMsgType Type, const QMessageLogContext& Context, const QString &Message)
    {
        OutputDebugString(reinterpret_cast<const wchar_t *>(Message.utf16()));
    }
    
    int main(int argc, char **argv)
    {
        // A GUI application
        QApplication app(argc, argv);
    
        // Custom handler
        qInstallMessageHandler(myMessageOutput);
        qDebug() << "Printed in the console using my message handler in a windows GUI application";
    
        // Default handler
        qInstallMessageHandler(0);
        qDebug() << "Also printed in the console!";
    
        // Show GUI here
        //MainForm *MF = new MainForm();
        //MF->show();
    
        return app.exec();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a project that will involve parsing HTML. After searching around,
I hope this isn't a stupid question, but after searching around for quite a
This title has been used many times but after searching around 5-6 examples, I
I got this code after searching around on stack overflow and it should work,
I am really posting this out of desperation after searching around a lot for
After searching a lot around, I decided to post this matter here. I am
I've been searching around the web for an answer to this one, but was
After searching around the web for about half an hour i've decided to ask
After searching around for months on and off I finally decided to post this
I came across a weird little problem. After searching around to fix the refreshing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.