No such file or directory #include <QtWidgets>
-
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
use this in your .pro file
-
I tried your 2 solutions, but i still have a problem:
A lot of functions are not declared.
This is the example I tested: childwidget (with the modifications you gave me)childwidget.pro:
@greaterThan(QT_MAJOR_VERSION, 4): QT += widgetsSOURCES = main.cpp
install
target.path = $$[QT_INSTALL_EXAMPLES]/widgets/tutorials/widgets/childwidget
INSTALLS += target
@main.cpp
@//! [main program]
//#include <QtWidgets>int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget window;
window.resize(320, 240);
window.setWindowTitle(QApplication::translate("childwidget", "Child widget"));
window.show();//! [create, position and show]
QPushButton *button = new QPushButton(
QApplication::translate("childwidget", "Press me"), &window);
button->move(100, 100);
button->show();
//! [create, position and show]
return app.exec();
}
//! [main program]
@And this is an extract of the errors (only the 2 first) i have when i compile:
@/opt/qt/5.2.1/gcc_64/examples/widgets/tutorials/widgets/childwidget/main.cpp:46: erreur : 'QApplication' was not declared in this scope
QApplication app(argc, argv);
^
/opt/qt/5.2.1/gcc_64/examples/widgets/tutorials/widgets/childwidget/main.cpp:46: erreur : expected ';' before 'app'
QApplication app(argc, argv);
^
@ -
you have to include the Qt classes you need, for a simple program like this you can include the whole module but I would not recommend that because it will drastically increase compile time.
@
#include <QApplication>
#include <QWidget>
#include <QPushButton>
@
essentially you have to include all Qt classes like this, if you want to do it right. :)if you are lazy or have a super fast computer you can include whole Qt modules at once with
@
#include <QtCore>
#include <QtGui>
#include <QtWidgets>
...
@
i would only use that if you need many classes from one module. -
Thank you,
with your help, I managed to run the example.I find it unfortunate that the examples do not work as they are.
That make the learning more difficult. -
Usually, the examples work as they are.
I have opened your examples/widgets/tutorials/addressbook/part1 with the Qt Creator, built it and had no errors.
How did you work with the example? -
That is strange, because, as I said, I just install qtcreator with the script qt-opensource-linux-x64-1.5.0-2-online.run, in the /opt directory/
Then, I open it and tried some examples, and I have the same problem eact time.
-
Do you open the examples from Qt creator directly? (Welcome -> examples)
they should work out of the box.And is there a reason you use and old version of Qt? I mean that is like 2 years old or something. :)
-
Do you open the examples from Qt creator directly? No : I opened with open file or project
And is there a reason you use and old version of Qt? I used the version found on the site web qt-opensource-linux-x64-1.5.0-2-online.run
I tried another version comming from the ubuntu deposite(Qt Creator 3.0.1) , but there was another problem because the binary /usr/bin/qmlpuppet was not installed (because not in the ubuntu deposite), and I did not find he way to install it.
-
I have Qt 5.2.1 running on my Ubuntu machine, using the online installer (qt-linux-opensource-1.5.0-x64-online.run in my case), worked like a charm so I don't know what you did. You have so weird bugs, I have no idea why, sorry.
-
I think we should try to find out, what happend to your install.
If you look at your Creator's About screen, do you see this:
Qt Creator 3.1.0 (opensource)
Based on Qt 5.2.1 (GCC 4.6.1, 64 bit)
Try to compare your Creator settings with "this: ":http://qt-project.org/doc/qtcreator-3.1/creator-configuring.html -
Thank form your help.
This is the version installed
@Qt Creator 3.0.1
Based on Qt 5.2.1 (GCC 4.8.2, 64 bit)
Built on Apr 9 2014 at 09:12:59
@And the version from the .run
@Qt Creator 3.1.0 (opensource)
Basé sur Qt 5.2.1 (GCC 4.6.1, 64 bit)
Compilé le Apr 14 2014 à 15:03:42
Depuis la révision 52592aa879@But it is strange because, now, the qtcreator installed from the unbuntu deposites is now working. Maybe the .run install added the missing files ?
-
As the Qt Creator 3.1.0 is the newest version it would be better to use it instead of 3.0.1 - but if you succeed with 3.0.1 you shouldn't have problems.
Perhaps you may give 5.3.0 a try when it's released in a few days. -
@tymop
Провести настройку комплектов под Qt5
На вкладке Проекты провести настройку проекта заново с верными компеляторами