Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

c++ class wouldn't build in bare bone QML application

$
0
0
I have a simple bare bone QML application and I just want to add a c++ class and use it from QML but I get error and it wouldn’t even build. Here is the code. #include <QGuiApplication> #include <QQmlApplicationEngine>   #include "mymodel.h"   int main(int argc, char *argv[]) {     QGuiApplication app(argc, argv);       MyModel model;       QQmlApplicationEngine engine;     engine.load(QUrl(QStringLiteral("qrc:/main.qml")));   //    engine.rootContext()->setContextProperty("_MyModel", &model);       return app.exec(); } And the class MyModel is: #ifndef MYMODEL_H #define MYMODEL_H   #include <QObject>   class MyModel : public QObject {     Q_OBJECT public:     explicit MyModel(QObject *parent = 0);   signals:   public slots:   };   #endif // MYMODEL_H the .cpp file of the class #include "mymodel.h"   MyModel::MyModel(QObject *parent) :     QObject(parent) { } When I build, I get the following error: main.obj:-1: error: LNK2019: unresolved external symbol "public: __thiscall MyModel::MyModel(class QObject *)" (??0MyModel@@QAE@PAVQObject@@@Z) referenced in function _main debug\QMLCalc1.exe:-1: error: LNK1120: 1 unresolved externals What is possibly wrong? I can’t even get to the setContextProperty() call yet.

Viewing all articles
Browse latest Browse all 4972

Trending Articles