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. qDebug print missplaced in run - not in code sequence
Forum Updated to NodeBB v4.3 + New Features

qDebug print missplaced in run - not in code sequence

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 237 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on 26 Oct 2019, 15:19 last edited by
    #1

    I hope I do not get flamed for this post, but I need an answer.
    I am using cout and qDebug to trace my code in real time.

    The attached snippet of code supposedly print qDebug " SINGLE message" first , than cout next.

    It does not, see attached console output.
    On top of that - the qDebug messages are printed in reverse order.

    I like to have some explanation why is that.

    I actually prefer using cout , and this weird sequence of qDebug makes my way of tracing the code flaky thus unusable.
    BUT if that is the way it works, I just won't use it.
    Thanks

    PS
    Sorry for messy code , it is work in progress

       if(BT_string_list.size())
        {
    
            cout << "ENTRY ********************************************" << endl;
    #ifdef DEBUG
            cout << endl;
            cout << "TRACE Current marker  " << __FUNCTION__ << endl;
            cout << "BT_string_list.size() OK           @line  list size  "
                 << BT_string_list.size() << "  " << __LINE__ << endl;
    
            // exit(42);
    
    
            cout << "\033[1;31mRED COLOR START " << endl;
            cout << "\033[1;31mTRACE START \n";
            cout << "*** TRACE file " << __FILE__ << endl;
            cout << " function " << __FUNCTION__ << endl;
            cout << "COLOR END   \033[0m " << dec << __LINE__ << endl;
            //exit(0);
    
            // scan_agent->BTScan_TEST_Print(scan_agent->BTLocalDeviceInfo.name());
    
            // BT_string_list.s
    
    
            cout << "\033[1;32mGREEN COLOR START " << endl;
            cout << "\033[1;32mTRACE START \n";
            cout << "*** TRACE file " << __FILE__ << endl;
            cout << " function " << __FUNCTION__ << endl;
            cout << "COLOR END   \033[0m " << dec << __LINE__ << endl;
    
    
            //qDebug ("message %d, says: %s",num,str);
    
    
            cout << "***************************************function " << __FUNCTION__ << endl;
    
    
    #ifdef DEBUG
            cout << "TRACE Current marker  " << __FUNCTION__ << endl;
            cout << "DEBUG HERE     @line " << __LINE__ << endl;
            cout << "function " << __FUNCTION__ << endl;
    #endif
    
    THIS GETS "DELAYED " IN PRINTING TO CONSOLE 
            qDebug() << "SINGLE DEBUG  message " << BT_string_list.size()<< ", says: "
                     << BT_string_list.at(0).name() << "@line " << __LINE__;
    
    
    #ifdef DEBUG
            cout << "TRACE Current marker  " << __FUNCTION__ << endl;
            cout << "DEBUG HERE     @line " << __LINE__ << endl;
            cout << "function " << __FUNCTION__ << endl;
    #endif
            //qDebug() << "DEBUG  message " << BT_string_list.size()<< ", says: " << BT_string_list.at(1).name();
    
    PRINTS IN CORRECT SEQUENCE 
    
            cout << "cout test #1 " << BT_string_list.at(0).name().toStdString() << endl;
            cout <<"cout test #2 " << BT_string_list.at(0).name().toLocal8Bit().constData() << endl;
    
    
    #ifdef DEBUG
            cout << "TRACE Current marker  " << __FUNCTION__ << endl;
            cout << "DEBUG HERE     @line " << __LINE__ << endl;
            cout << "function " << __FUNCTION__ << endl;
    #endif
    
    
    #endif
    
            cout << "EXIT ******************************************" <<endl;
    
        }
        else
    
    ***************************************function on_scan_pressed
    TRACE Current marker  on_scan_pressed
    DEBUG HERE     @line 182
    function on_scan_pressed
    TRACE Current marker  on_scan_pressed
    DEBUG HERE     @line 189
    function on_scan_pressed
    
    PRINTS IN CORRECT SEQUENCE 
    
    cout test #1 z-desktop
    cout test #2 z-desktop
    TRACE Current marker  on_scan_pressed
    DEBUG HERE     @line 197
    function on_scan_pressed
    EXIT ******************************************
    DEBUG  " scan_agent->BTScan_TEST_Print "  @line  24 
    
    DEBUG  "z-desktop"  @line  24 
    
    DELAYED AND IN REVERSE ORDER OF qDebug calls  
    
    SINGLE DEBUG  message  1 , says:  "z-desktop" @line  186
    /media/z/DOC_COPY_LABEL/Projects /QT_TEST/TEST_Splitter/application_1/build-application-Desktop-Debug/application exited with code 0
    
    1 Reply Last reply
    0
    • C Online
      C Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 26 Oct 2019, 15:47 last edited by
      #2

      I don't see what's wrong here - qDebug() and std::cout are two completely different things so why should the order between those two match when it is printed to stdout?

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3

      1/2

      26 Oct 2019, 15:19

      • Login

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