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. QTextStream to console: endl and flush slow down program considerably?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.7k 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.
  • S Offline
    S Offline
    soukyuu
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • S Offline
        S Offline
        soukyuu
        wrote on last edited by
        #3

        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.

        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