qDebug() behavior vs std:cout



  • 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


  • Moderators

    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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.