Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Writing debug information both in file and Windows debugger
Forum Updated to NodeBB v4.3 + New Features

Writing debug information both in file and Windows debugger

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 7.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    usamytch
    wrote on last edited by
    #1

    Good day, colleagues!

    How could I write debug info both to custom place (e. g. in file) and to default location (e. g. Windows debug console)?

    Currently I use qInstallMsgHandler with this handler:

    @void My_Message_Handler (QtMsgType message_type, const char * message) {

    QString debug_string;
    
    switch (message_type) {
    case QtDebugMsg : debug_string = QString(message);
        break;
    ...
    
    QFile log_file (LOG_FILENAME);
    log_file.open (QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
    QTextStream text_stream (&log_file);
    text_stream << debug_string << '\n';
    

    }@

    What should I add to my code to write to the default debug output too?

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #2

      Easiest way is to use a different logger than Qt's. QxtLogger comes to mind. That one can also easily integrate with Qt (register itself as the Qt Message handler), so your qDebug()'s still end up in your log file.

      I requested a merge request for a logger engine I wrote for it for the Windows logger stream. I don't think it is in the 0.6 version (yet), but it should still be in the repo.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        florent.revelut
        wrote on last edited by
        #3

        What we dot here in our custom logger is simply
        std::cout<<debugString.toStdString();
        in addition to writing to file.

        If stdout doesn't please you, you can use OutputDebugString
        http://msdn.microsoft.com/en-us/library/aa363362(v=vs.85).aspx
        to print in debug console

        [EDIT: fixed link formatting, Volker]

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #4

          adding
          CONFIG += console

          should enable u to output messages to your windows console directly using qDebug() .. so on

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [quote author="chetankjain" date="1300264091"]adding
            CONFIG += console

            should enable u to output messages to your windows console directly using qDebug() .. so on[/quote]
            The windows console is not the same as the debugger stream.

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved