Results 1 to 3 of 3

Thread: console output on windows and ubuntu

  1. #1
    Join Date
    Sep 2010
    Posts
    10
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default console output on windows and ubuntu

    Hi all,

    I'm quite new to Qt and i have a question about something whether or not
    something is normal:

    I made a very simple main function:
    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <iostream>
    3.  
    4. int main( int argc, char* argv[] ){
    5. QApplication app( argc, argv);
    6. std::cout<<"initialisation successful!";
    7. return app.exec();
    8. }
    To copy to clipboard, switch view to plain text mode 

    When i run it( compiling gave no errors), nothing is printed to the terminal
    in ubuntu, unless i use std::cout.flush(), then it is printed. But in windows,
    nothing is printed at all.

    Something else is that my application never ends.

    Is this normal?

    hannesvdc

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: console output on windows and ubuntu

    Quote Originally Posted by hannesvdc View Post
    unless i use std::cout.flush()
    That's because the output is buffered.

    But in windows, nothing is printed at all.
    You need to add "CONFIG += console" to your .pro file.

    Something else is that my application never ends.
    That is because you start the application event loop. This will run for ever until you tell it to stop.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: console output on windows and ubuntu

    This is perfectly normal behaviour.
    nothing is printed to the terminal
    in ubuntu, unless i use std::cout.flush(), then it is printed.
    Streams are buffered by default in unix systems so you have to flush a stream (e.g. by sending it a newline character - \n) to empty the buffers.
    But in windows, nothing is printed at all.
    Add CONFIG+=console to your project file and rerun qmake.

    Edit: Beaten to it
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Windows debuging output?
    By llemes4011 in forum Qt Programming
    Replies: 3
    Last Post: 3rd August 2010, 01:01
  2. No output to console
    By Morea in forum Newbie
    Replies: 6
    Last Post: 1st November 2007, 23:51
  3. convert console to windows app
    By Max Yaffe in forum Newbie
    Replies: 1
    Last Post: 13th June 2007, 16:38
  4. Replies: 52
    Last Post: 10th December 2006, 15:32
  5. No console output in Mac OSX using Qt4
    By popoholic in forum Qt Programming
    Replies: 2
    Last Post: 26th September 2006, 02:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.