Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    qDebug() behavior vs std:cout

    General and Desktop
    2
    2
    3151
    Loading More Posts
    • 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
      Zingam last edited by Zingam

      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 Reply Quote 0
      • Chris Kawa
        Chris Kawa Moderators last edited by

        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 Reply Quote 0
        • First post
          Last post