[Solved] QApplication: No such file or directory
-
I got Qt5 installed on Opensuse 12.2.
I tried to compile some example project that compiled successfully on Qt 4.8.
Now I get error message "QApplication: No such file or directory"
I think the PATH to library is missing while I installed locally on /home/Where should I edit?
-
How do you include QApplication header? In Qt5, it resides in <QtWidgets/QApplication>, while in Qt4 it was <QtGui/QApplication>.
-
I think the module isn't added in .pro file, so did you added QT += widgets in your .pro file?
//anyway if the module is added the header can be included with #include <QApplication> you don't need <QtWidgets/QApplication> or <QtGui/QApplication> in Qt4 (that works with both Qt4 and 5)
-
Adding QT += widgets in .pro file made the trick. Thanks.
-
Why does qmake not include these, or what must one do in the source to ensure qmake auto generates this line in the .pro file ?
-
qmake will never generate anything in your .pro file. Those files are config files for qmake to use, not the other way around. If you create a new project in recent versions of Qt Creator, this line will be added for you in standard app template.
-
Ooh ok, that make more sense now, thanks for the reply.
Sorry for hijacking the thread by the way :D
-
The "Adding QT += widgets in .pro file" really helped me as well. Thanks.
-
I'm happy, too. I solved.
Why qmake --project is doing a so simple task in a wrong way?
-
can qmake -project add "QT += widgets" to .pro automatically ?
-
Just to say what happened to be my problem, it was a dumb error:
I was following a guide that had me open an empty QT project, which gave me a .pro file but left it empty. I had filled in some data and "TEMPLATE = application" as they has mentioned it. I already had the "widgets" line but it still couldn't find the library as I included it in the .cpp file. When I changed it to "TEMPALTE = app" the .pro file was parsed, and the file to include resolved correctly (QApplication).
-
@sierdzio
I have add <QtWidgets/QApplication> to mainwindow.h file and
QT += widgets in .pro file but still "error : No such file or directory" occurs . -
@Mijaz said in [Solved] QApplication: No such file or directory:
<QtWidgets/QApplication>
It's
#include <QApplication>
-
@jsulm
I have changed but error still error not resolved. -
@Mijaz Please show your pro file and main.cpp
-
@jsulm Hello, I am having a similar issue to @Mijaz. I am trying to use Qt 5.11 to cross compile for a STM32MP157c-DK2 development board. I have successfully loaded images to the board from a qml file but my cpp files are riddled with errors including "use of undeclared identifier 'QCoreApplication'. I have tried adding #include <QApplication> and QT += widgets with no luck. Here is my main.cpp file and my pro file.
main.cpp
#include <QGuiApplication> #include <QQmlApplicationEngine> #include <QApplication> #include <QLabel> #include <QQmlEngine> #include <QTextCodec> #include <QtGui> int main(int argc, char *argv[]) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); QGuiApplication app(argc, argv); QQmlApplicationEngine engine; const QUrl url(QStringLiteral("qrc:/main.qml")); QObject::connect(&engine, &QQmlApplicationEngine::objectCreated, &app, [url](QObject *obj, const QUrl &objUrl) { if (!obj && url == objUrl) QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.load(url); return app.exec(); }
pro file
QT += quick widgets core gui CONFIG += c++11 qmltypes qt # The following define makes your compiler emit warnings if you use # any Qt feature that has been marked deprecated (the exact warnings # depend on your compiler). Refer to the documentation for the # deprecated API to know how to port your code away from it. DEFINES += QT_DEPRECATED_WARNINGS # You can also make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. # You can also select to disable deprecated APIs only up to a certain version of Qt. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 SOURCES += \ main.cpp RESOURCES += qml.qrc # Additional import path used to resolve QML modules in Qt Creator's code model QML_IMPORT_PATH = # Additional import path used to resolve QML modules just for Qt Quick Designer QML_DESIGNER_IMPORT_PATH = # Default rules for deployment. #qnx: target.path = /tmp/$${TARGET}/bin #else: unix:!android: target.path = /opt/$${TARGET}/bin #!isEmpty(target.path): INSTALLS += target TARGET = stm32mp1Test target.files = stm32mp1Test target.path = /home/root INSTALLS += target
Thanks for the help.
-
@braden_sun Did you cross compile Qt for your device?
Why do you include QApplication and QGuiApplication if you want to use QCoreApplication? You need to include QCoreApplication...