3

I am currently using QT Creator 3.2.1 with Qt 5.3.2 (as required by my current project) on Windows 7 (64 bits, Ultimate). I am currently working on a GUI project

I am unable to see any qDebug messages in the Application Output window despite already done the following:

  1. Having the appropriate QDebug code
  2. Building the project in Debug mode
  3. Using "CONFIG += openssl-linked" "CONFIG += console" as additional arguments for building the project
  4. Not defining QT_NO_DEBUG_OUTPUT at all
  5. Confirming that I have a debugger (GDB from MinGW 4.8.2 32 bit installed during installing QtCreator)

May I know what else should I try? Thanks!

darkarn
  • 53
  • 1
  • 3
  • Make sure that you have no other program open that grabs the output streams such as debugview (only one application receives output from GUI applications at a time). You also might want to try a newer Qt Creator version (current is 4.2.0). – E4z9 Jan 02 '17 at 11:02
  • Thanks, how do I exactly check for that? (I dont think I have seen any lines using debugview for example). As for using a newer Qt Creator, let me see if it will still work with Qt 5.3.2... – darkarn Jan 02 '17 at 13:32
  • How do you start the program? Is it 'Start Debugging' or 'Run'? Is there qInstallMessageHandler call in the app code? – Alexander V Jan 02 '17 at 17:14
  • You should try a newer version of QTCreator – jpo38 Jan 02 '17 at 20:04
  • @AlexanderVX: Yes, there's such a call in the main.cpp qInstallMessageHandler(customMessageHandler); Also, I used "Start Debugging" all these while to start the program – darkarn Jan 02 '17 at 22:41
  • @jpo38: Ok, I will go see if I can get the newer Qt Creator to work with the required Qt version – darkarn Jan 02 '17 at 22:44
  • I am now using Qt Creator 4.2 with Qt 5.3.2 and I am seeing these messages: Could not load shared library symbols for 56 libraries, e.g. C:\Windows\system32\ntdll.dll. Use the "info sharedlibrary" command to see the complete listing. Do you need "set solib-search-path" or "set sysroot"?Could not load shared library symbols for C:\Windows\SysWOW64\imm32.dll. – darkarn Jan 02 '17 at 23:11
  • @darkam The issue appears to be very simple. Somebodies code is just stealing debug messages from the console so you don't see them. Read here: http://stackoverflow.com/questions/14643293/how-does-qt5-redirect-qdebug-statements-to-the-qt-creator-2-6-console – Alexander V Jan 02 '17 at 23:33
  • @AlexanderVX: Thanks! That appeared to have done the trick; changing qInstallMessageHandler(customMessageHandler); to qInstallMessageHandler(0); works! How should I up-rep you or shall I go ahead and answer the question? – darkarn Jan 03 '17 at 16:39
  • I've added the answer. Hopefully that is the most common case for not seeing debug messages in Qt Creator. – Alexander V Jan 03 '17 at 18:41

2 Answers2

26

This did it for me on Arch Linux

Qt creator > Tools > Options > Kits, select your kit, find Environment, click change and add:

   QT_ASSUME_STDERR_HAS_CONSOLE=1

Now the Message can be printed in the Application Output with something like that:

   qDebug() << "User clicked on the button!";

Screenshot on how to enable qDebug message

And than you should see something in the program like so:

qDebug output screenshot

Community
  • 1
  • 1
Ingo Mi
  • 999
  • 12
  • 26
  • 1
    Why is QT_ASSUME_STDERR_HAS_CONSOLE=1 necessary for qDebug() messages to show up on Qt Creator? Should this bug be reported to Qt? – nyanpasu64 Jun 18 '20 at 00:12
  • @nyanpasu64 *Bill Gates would say: "I wouldn't call it "a bug" - It's a feature" ;)* Jokes aside, the Qt Creator is kept as lean as possible. I guess in Qt6 or along the way some check boxes might be appear to make customization more easy like this debug stuff or selecting the c++ version without having to edit the templates and so on. A bug would be needed to be issued if the debug function wouldn't work besides adding that line - but its working fine. – Ingo Mi Jun 19 '20 at 12:11
  • On some Linux distros (like OpenSUSE which I'm using), Qt debug messages are sent to journalctl instead of the console. Maybe Qt programs run directly in a console have errors sent to console rather than journalctl, but Qt Creator isn't detected as a console. – nyanpasu64 Jun 20 '20 at 03:02
  • 2
    Thanks, this worked for me on one Arch installation, whereas in the other (same Qt version) I didn't have to add the flag to get console output. – Herr von Wurst Aug 10 '20 at 06:18
3

I don't get any debug messages supposed to be printed out by qDebug() in Qt Creator? What could be the reason for that?

It is common to redefine the standard Qt debug output in Qt apps via the custom log message handler but we can still take care of making debug messages to reach the debug console:

// example for custom message handler
void customLogHandler(QtMsgType type, const QMessageLogContext& context,
                      const QString& msg)
{
   // send the data to log file via the other thread
   emit writeToFile(type, context, msg);

   // now output to debugger console
#ifdef Q_OS_WIN
    OutputDebugString(text.toStdWString().c_str());
#else
    std::cerr << text.toStdString() << std::endl;
#endif
}

void main()
{
   // custom handler start
   qInstallMessageHandler(&customLogHandler);

   // other app initializations
}
Alexander V
  • 8,351
  • 4
  • 38
  • 47
  • Thanks! I found similar looking code in my project too, just that it was placed in a header file. I wonder if it should be placed back in main.cpp instead. For now I will go with using qInstallMessageHandler(0); as I will like to fix more urgent bugs first. – darkarn Jan 05 '17 at 05:20