Results 1 to 5 of 5

Thread: No result by using "cout", but by "qDebug()"

  1. #1
    Join Date
    Apr 2021
    Posts
    4
    Qt products
    Qt5

    Default No result by using "cout", but by "qDebug()"

    I typed two examples for "Hello World" program, one using "cout" but doesn't print anything, and the other by using "qDebug()" and printed the words, why "cout doesn't work?

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


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

  2. #2
    Join Date
    Dec 2008
    Posts
    18
    Thanks
    4
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: No result by using "cout", but by "qDebug()"

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QCoreApplication a(argc, argv);
    4.  
    5. std::cout << "Hello World!\n";
    6.  
    7. std::cout << "Hello World!" << std::endl;
    8.  
    9. qDebug() << "Hello World!";
    10.  
    11. return a.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2021
    Posts
    4
    Qt products
    Qt5

    Default Re: No result by using "cout", but by "qDebug()"

    I modified code like you explained, it still doesn't work:

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

  4. #4
    Join Date
    Dec 2008
    Posts
    18
    Thanks
    4
    Thanked 3 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: No result by using "cout", but by "qDebug()"

    You need the newline "\n" or "<< std::endl;"

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: No result by using "cout", but by "qDebug()"

    I modified code like you explained, it still doesn't work
    Look at this example from the Qt Wiki. You will have a much easier time if you work through the examples and tutorials instead of just writing code without a better understanding of Qt.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  6. The following user says thank you to d_stranz for this useful post:

    peppermg (22nd April 2021)

Similar Threads

  1. Replies: 1
    Last Post: 20th November 2015, 11:02
  2. QSqlError("", "Parameter count mismatch", "")
    By Alberto7 in forum Newbie
    Replies: 2
    Last Post: 9th October 2015, 23:09
  3. Replies: 3
    Last Post: 16th March 2015, 08:31
  4. Replies: 3
    Last Post: 8th July 2008, 20:37
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 20:05

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.