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() behavior vs std:cout

qDebug() behavior vs std:cout

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.6k Views
  • 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.
  • Z Offline
    Z Offline
    Zingam
    wrote on last edited by Zingam
    #1

    I am looping through items like that:

    for (Puzzle* puzzle: this->puzzles)
    {
        if (puzzle->isLoaded)
        {
            std::cout << puzzle->puzzleInfo->name << std::endl;
            std::cout << puzzle->puzzleInfo->text << std::endl;
    
            const char* const path = "Puzzles/Puzzle001";
            puzzle->run(path);
        }
    }
    

    run is a function pointer that points to a function in a dll. It does nothing but to output via std:cout the value of the "path" variable.

    If I replace the std::cout statements above with qDebug. I am not getting the otput in the expected order but rather:

    Create an Image of Uniform Gray Level
    Parameters: Puzzles/Puzzle001
    Create an Image of Uniform Gray Level
    Create an Image of Uniform Gray Level
    Create an Image of Uniform Gray Level
    Parameters: Puzzles/Puzzle001
    Parameters: Puzzles/Puzzle001
    Parameters: Puzzles/Puzzle001

    (I've shortened this a bit). Why is that so?

    What I'd expect is:

    Create an Image of Uniform Gray Level
    Parameters: Puzzles/Puzzle001
    Create an Image of Uniform Gray Level
    Parameters: Puzzles/Puzzle001
    Create an Image of Uniform Gray Level
    Parameters: Puzzles/Puzzle001
    Create an Image of Uniform Gray Level
    Parameters: Puzzles/Puzzle001

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      qDebug does not use std::cout internally so there's no wonder that they are not synchronized. They have separate buffering arrangements and different code paths from your code to console output, or wherever you're viewing their output. Some of it will be asynchronous (though serialized) so you will see properly ordered messages within single method output but not when mixing the two.

      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