I try to learn C++ with Qt following examples from a book. On very first example including Qt I have a compilation error:
$ g++ -Wall qtdemo.cpp
qtdemo.cpp:1:19: fatal error: QString: No such file or directory
compilation terminated.
The g++ works fine if I don't include any Qt library.
I try to run the same program using Qt Creator and it works if I do a "Qt Console application" but shows error if I do a "Plain C++ application".
I tried to give a path to QString
after g++ command, different configuration etc. It seems g++ can't see Qt at all.
I even installed Qt5 on top of already existing on Ubuntu 16.04 Qt4.
When I check if I have Qt installed it looks everything should be fine:
$ locate QString
/opt/Qt5.7.0/5.7/Src/qtbase/include/QtCore/QString
...
/opt/Qt5.7.0/5.7/gcc_64/include/QtCore/QString
...
/usr/include/qt4/QtCore/QString
...
$ qmake -v
QMake version 2.01a
Using Qt version 4.8.7 in /usr/lib/x86_64-linux-gnu
The code I try to run:
#include <QString>
#include <QTextStream>
QTextStream cout(stdout);
QTextStream cin(stdin);
int main() {
QString s1("This "), s2("is s "), s3("string");
s1 += s2; //concatenation
QString s4 = s1+s3;
cout << s4 << endl;
cout << "The length of that string is " << s4.length() << endl;
cout << "Enter a sentence with withspace: " << endl;
s2 = cin.readLine();
cout << "Here is your sentence: \n" << s2 << endl;
cout << "The length of your sentnce is: " << s2.length() << endl;
return 0;
}
I don't know how to make Qt application works from command line with g++ and where the error comes from.