Reputation: 17
I'm working on a class derived from QObject, I'm compiling for android and using android qt6.2.2 Clang arm64_v8a
kit. To the default QQuickApp in qt creator I just added the following header file
MyObject.h
#ifndef MYOBJECT_H
#define MYOBJECT_H
#include <QObject>
class MyObject : public QObject {
Q_OBJECT
public:
signals:
public slots:
private:
};
#endif // MYOBJECT_H
main.cpp
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <MyObject.h>
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
QQmlApplicationEngine engine;
const QUrl url(u"qrc:/ParseErrorWorkOn/main.qml"_qs);
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();
}
main.qml
import QtQuick
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
}
this is the *.pro file:
QT += quick
QT += core
SOURCES += \
main.cpp
resources.files = main.qml
resources.prefix = /$${TARGET}
RESOURCES += resources
# 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
HEADERS += \
MyObject.h
MyObject has signals and slots then I added Q_OBJECT
, but compiling I got the following error
error: Parse error at "__attribute__"
make: *** [Makefile:700: moc_MyObject.cpp] Error 1
make: *** Waiting for unfinished jobs....
I also compiled with Mingw64 for windows and it works fine.
I cleaned up and reran qmake but nothing changed.
Commenting Q_OBJECT
it compiles fine, but I need signals and slots. How can I fix this? thank you in advance.
Upvotes: 0
Views: 263
Reputation: 17
I figured this out, I made a mistake setting qmake system behaviour() when parsing
on use global setting
instead to set it on run
in the project configuration window.
Upvotes: 1