QTextStream to console: endl and flush slow down program considerably?

  • This is mainly curiosity, but it appears that
    QTextStream out(stdout);
    out << "Test.\n"; // fast, does not flush (delayed output on console)
    out << "Test." << endl; //slow, flushes and appends a newline
    out << "Test.\n" << flush; //slow as above

    "Fast" being ~2.1 seconds, "slow" being ~3 seconds for a list of 6000 files. I'm guessing this has something to do with the << operator and what's going on "behind the scenes".

    Question is, how do I display the message without slowing down the output?
    Is there a better (=faster) way to print non-debug messages for the user?
    Should I just make a --verbose switch in case the user wants to see the output?

  • Hi,

    You can look at Qt's source if your curious enough.

    If you really want "fast", I suggest you use <stdio.h> API's. If you do so, make sure that you convert QString's to appropriately encoded char arrays.

  • In my tests using QTextStream without flushing is about as fast as stdio.h APIs, so I think I'll just use that. Thanks for the reply.

Log in to reply

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