Reputation: 123
I have looked everywhere and the solution to this is to add a line of code to a '.pro' file in my project. I cannot see any such files though! I can see a qbs file, the main.cpp file and a xcode.qbs file.
This is how I started: using a Mac, I installed Qt Creator 4.8 (Clang v5.12) and I created a 'plain C++ project' which uses Qmake.
I am using the {} to initialise a variable but it won't allow me to. I had a similar problem with Eclipse and found a solution. Any help, please?
This is the code I am testing:
#include <iostream>
int main()
{
int a{5};
std::cout << a;
return 0;
}
The error code for the line where I define a is: "/Users/xxxxxx/Coding/HelloEarth/main.cpp:5: error: expected ';' at end of declaration"
What should I do?
Upvotes: 1
Views: 1237
Reputation: 3186
This is the simplest approach to creating a qt project:
Foo/
in your Desktop: ~$ cd Desktop; mkdir Foo/
~$ cd ~/Desktop/Foo
~$ touch Foo.pro main.cpp
.profile
or .bashrc
, then you can type ~$ qtcreator
in your terminal to run qt. Otherwise, click on the QtCreator App from the applications.File -> Open project
and select the Foo.pro
file.Foo.pro
file open in Qt. Now enter the following lines in the Foo.pro file and hit save (Ctrl+S).CONFIG += c++11 console TARGET = My_Foo SOURCES += main.cpp
Build option
, untick shadow build
and under the Run option
, untick Run in terminal
.Ctr+S
(to save), Ctrl+B
(to build the project) and Ctrl+R
(to run).Up until step 7, you can do it using the GUI, by selecting Create new Project and then select console application. Btw, on mac use Cmd instead of Ctrl.
Also make sure you have the correct compilers setup. (https://doc.qt.io/qtcreator/creator-tool-chains.html)
Upvotes: 1