My first console C++ program on Qt Creator
-
Hello all,
I've started learning Linux and it's a good time to use the IDE (Qt Creator 4.8) for C++ console apps too.
So after creating a Plain C++ Application project I wrote a simple hello world program and ran it.
Here's the screenshot:What do I get these many errors please?
I though the IDE has the compiler for C++ console apps too.
How to solve these please? -
Here it works
#include <QCoreApplication> #include <iostream> #include "QDebug" using namespace std; int main(int argc, char *argv[]) { cout << "Hello World!!!" << endl; qDebug() << "Hello World!!!"; // Qt way return 0; } Maybe you have got problems with the chosen platform.
-
Hi,
Can you show your .pro file ?
-
@tomy said in My first console C++ program on Qt Creator:
What do I get these many errors please?
For now, ignore those error messages and try to build and run your application anyway. Does it work? If not, do you see any new error messages?
-
For now try this:
- Remove
CONFIG -= qt
- Add
QT =
- Remove
-
Did you re-run qmake after modifying the .pro file ?
-
What do you get if you call make after that ?
-
Yes, that's it.
-
@SGaist
Thanks. I did it and it showed the output I wanted on the Terminal.
But still I see the errors and red lines on the code! :(Why while the program runs successfully does Qt Qreator show them? And how to get rid of them. They are ugly indeed.
-
Try changing the code model used by Qt Creator.
-
@tomy said in My first console C++ program on Qt Creator:
Of course. I get 6 issues. 5 of them are errors and one warning, as shown in the screenshot in the first post here.
The screenshot in your first post shows errors and warnings from the static code analyzer, not from your compiler. We can tell because the red circle and yellow triangles are "hollow". Errors and warnings from your compiler have "filled" circles and triangles.
Try to build and run your code to activate your compiler. Does it run successfully?
Anyway, you are seeing these errors because the static code analyzer thinks you are writing C code (not C++ code) for some reason. You can disable it by clicking Help > About Plugins... and unchecking C++ > Clang Code Model
@tomy said in My first console C++ program on Qt Creator:
If using qmake in Linux (Ubuntu) is this way, I did and below is the output. My project is on the Desktop named "hello_world".
I believe @SGaist meant running qmake from within Qt Creator, when your project is open. The menu item is Build > Run qmake.
Running qmake in the console does not change anything in Qt Creator.