No such file or directory #include <QtWidgets>
-
Hello,
I am a beginner with qt, and I just download and install the last vesion of qt with this link "qt-opensource-linux-x64-1.5.0-2-online.run":http://download.qt-project.org/official_releases/online_installers/qt-opensource-linux-x64-1.5.0-2-online.runThen, I tried some examples to understand how qt works, but i have the save error with each examle I tried. This is an example
@/opt/qt/5.2.1/gcc_64/examples/widgets/tutorials/addressbook/part1/addressbook.cpp:41: erreur : QtWidgets: No such file or directory
#include <QtWidgets>@always the same error : @erreur : QtWidgets: No such file or directory #include <QtWidgets>@
Is there anything especial to do to work with the examples ?
what is the problem ?
Thank a lot for your help.
-
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. -
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 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 ?