Results 1 to 4 of 4

Thread: cout in Qt

  1. #1
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question cout in Qt

    Hi all,

    I want to use cout in Qt. I have this code:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <iostream>
    3.  
    4. using namespace std;
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication a(argc, argv);
    9.  
    10. cout << "finish";
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

    but the text "finish" doesn't appear.

    What's wrong?

    Regards.

  2. #2
    Join Date
    May 2010
    Location
    Romania
    Posts
    1,021
    Thanks
    62
    Thanked 260 Times in 246 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: cout in Qt

    Do you have CONFIG += console in your .pro file? Tell us more about what is happening: what os are you using? the console/terminal doesn't appear? or it appears without output?

    And why are you using a QApplication and it's exec()? Do you really need that, because it create an event loop that you will want to close (by connecting a signal to it's quit slot)

  3. #3
    Join Date
    May 2012
    Posts
    99
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: cout in Qt

    Quote Originally Posted by Zlatomir View Post
    Do you have CONFIG += console in your .pro file? Tell us more about what is happening: what os are you using? the console/terminal doesn't appear? or it appears without output?
    No, I have added CONFIG += console in my .pro file and now I can see the output, but when the application is closed. I'm using MS Windows. I have run the project from Qt Creator and I expected see the output in "Application output".

    Quote Originally Posted by Zlatomir View Post
    And why are you using a QApplication and it's exec()? Do you really need that, because it create an event loop that you will want to close (by connecting a signal to it's quit slot)
    No, I have created an empty project by "Qt Gui Application" and QApplication and it's exec() appear by default. What's the best way to create a console project?

    Regards!

  4. #4
    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: cout in Qt

    Quote Originally Posted by qt_developer View Post
    No, I have added CONFIG += console in my .pro file and now I can see the output, but when the application is closed.
    Add " << endl".
    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. Qt Creator where is cout in Qt Creator
    By hqking1988 in forum Qt Tools
    Replies: 8
    Last Post: 12th September 2019, 22:32
  2. where is cout
    By hqking1988 in forum General Programming
    Replies: 3
    Last Post: 22nd August 2010, 03:35
  3. cout problem
    By mickey in forum General Programming
    Replies: 3
    Last Post: 2nd March 2007, 18:12
  4. How to cout in Qt ?
    By probine in forum Qt Programming
    Replies: 4
    Last Post: 15th December 2006, 00:47
  5. std::cout displaying a hex value instead of a string.
    By johnny_sparx in forum Qt Programming
    Replies: 2
    Last Post: 8th April 2006, 08:55

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.