Results 1 to 10 of 10

Thread: QtCreator - Plain C++ Project Hello World only runs without "endl"

  1. #1

    Question QtCreator - Plain C++ Project Hello World only runs without "endl"

    Hi all,

    I have installed Qt 5.0.1 with QtCreator 2.6.2 on Windows 7 and experience a strange behaviour. When I start a new plain C project, everything works fine (the standard Hello World is printed to the console). However when I start a new plain C++ project, again the Hello World is printed to the console but a new (native Microsoft) window pops up and tells me that myprogramname.exe doesn't work anymore . And what I really don't get is the fact that if I delete the part "<< endl" everythings run without problems!

    It seems like Qt is having trouble with endl. When I hover endl with my cursor, it says something like "QTextStream & endl...", whereas hovering cout results in "std::cout". Is this perhaps my problem? Can you replicate my problem on your PC? What can I do to fix this problem?

    main.cpp
    Qt Code:
    1. #include <iostream>
    2.  
    3. using namespace std;
    4.  
    5. int main()
    6. {
    7. cout << "Hello World!" << endl;
    8. return 0;
    9. }
    To copy to clipboard, switch view to plain text mode 

    myprogramname.pro
    Qt Code:
    1. TEMPLATE = app
    2. CONFIG += console
    3. CONFIG -= app_bundle
    4. CONFIG -= qt
    5.  
    6. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    clean and rebuild.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    Clean and rebuild does not work. It even happens if I start a completely new plain C++ Project and just run it..

  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    what compilers have you got installed?


    Added after 1 5 minutes:


    compiling by using the command line only, what happens?
    Last edited by amleto; 20th April 2013 at 18:04.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    I have the lastest MinGW package including g++. "g++ main.cpp -o myprogram" compiles without error notification and running the program in the command line also works.

  6. #6
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Platforms
    Windows

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    File->new-> then do the basic console application and it wont have the ui, or header it will be something like
    Qt Code:
    1. main(argc, argv[]) { application w(argc); w.exec() }
    To copy to clipboard, switch view to plain text mode 
    and then just put something like this:
    Qt Code:
    1. #include <iostream>
    2. using namespace std;
    3. int main()
    4. {
    5. cout << "Hello world." << endl;
    6. return(0);
    7. }
    To copy to clipboard, switch view to plain text mode 

  7. #7

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    @giblit: Thank you for your answer, but my intention was not to use the Qt console. I want to do this as a plain C++ program with QtCreator (it is for a programming course at university and our tutors don't know Qt). And Qt has the plain C++ feature for things exactly like this, so it should work without the Qt console.

    What makes me wonder is that everything works fine if I don't use the endl statement...

  8. #8
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Platforms
    Windows

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    using the qt c++ console is the same as using any other ide.
    just erase the default code and put what I put.

    It has the premade pro file that way so you don't have to do the include += console manually that is the only difference. and the endl works perfectly fine for me

    basically what you said is that using the cmd with microsoft visual is different than using cmd through qt or using cmd through ctrl+r(cmd)
    only time consoles are different is when you are on linux because there are several terminals(Konsole as an example) but Konsole there is the same on Genay as it is on Qt and same with any other terminal/console

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    show th ebuild output from when it doesn't work - what is the difference between that and when you manually build from the command line (and the program does work)?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  10. #10
    Join Date
    Feb 2013
    Posts
    71
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Platforms
    Windows

    Default Re: QtCreator - Plain C++ Project Hello World only runs without "endl"

    all I know is its easier to just do file->new->Qt Console Application then clear the cpp and make it what you want
    the .pro for the Qt Console Application is:
    Qt Code:
    1. QT += core
    2.  
    3. QT -= gui
    4.  
    5. TARGET = HelloWorld // Project name
    6. CONFIG += console
    7. CONFIG -= app_bundle
    8.  
    9. TEMPLATE = app
    10.  
    11.  
    12. SOURCES += main.cpp
    To copy to clipboard, switch view to plain text mode 
    I've never had a problem with endl

Similar Threads

  1. Why this doesn't work? qDebug() << "Test" << std::endl;
    By grayfox in forum Qt Programming
    Replies: 4
    Last Post: 1st June 2011, 10:19
  2. Replies: 3
    Last Post: 15th February 2010, 17:27
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. Setting up qmake to run "Hello World"
    By Rolsch in forum Newbie
    Replies: 2
    Last Post: 27th May 2006, 02:37

Tags for this Thread

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.