PDA

View Full Version : QtCreator - Plain C++ Project Hello World only runs without "endl"



dartsmil
20th April 2013, 15:13
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 :confused:. 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

#include <iostream>

using namespace std;

int main()
{
cout << "Hello World!" << endl;
return 0;
}

myprogramname.pro

TEMPLATE = app
CONFIG += console
CONFIG -= app_bundle
CONFIG -= qt

SOURCES += main.cpp

amleto
20th April 2013, 16:21
clean and rebuild.

dartsmil
20th April 2013, 16:48
Clean and rebuild does not work. It even happens if I start a completely new plain C++ Project and just run it..

amleto
20th April 2013, 18:04
what compilers have you got installed?

Added after 1 5 minutes:

compiling by using the command line only, what happens?

dartsmil
20th April 2013, 20:25
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.

giblit
20th April 2013, 20:32
File->new-> then do the basic console application and it wont have the ui, or header it will be something like
main(argc, argv[]) { application w(argc); w.exec() } and then just put something like this:

#include <iostream>
using namespace std;
int main()
{
cout << "Hello world." << endl;
return(0);
}

dartsmil
20th April 2013, 20:52
@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...

giblit
20th April 2013, 21:26
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

amleto
20th April 2013, 21:54
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)?

giblit
20th April 2013, 22:58
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 += core

QT -= gui

TARGET = HelloWorld // Project name
CONFIG += console
CONFIG -= app_bundle

TEMPLATE = app


SOURCES += main.cpp
I've never had a problem with endl