Reputation: 11
I build a cm-lib.dll
QT -= gui
TARGET = cm-lib
TEMPLATE = lib
CONFIG += c++14
DEFINES += CMLIB_LIBRARY
......
#ifndef MASTERCONTROLLER_H
#define MASTERCONTROLLER_H
#include <QObject>
#include <QString>
#include "cm-lib_global.h"
namespace cm{
namespace controllers{
class MasterController : public QObject
{
Q_OBJECT
Q_PROPERTY(QString ui_welcomeMessage MEMBER welcomeMessage CONSTANT)
public:
explicit MasterController(QObject *parent = nullptr);
QString welcomeMessage = "This is MasterController to Major Tom";
signals:
public slots:
};
}}
#endif // MASTERCONTROLLER_H
#include "master-controller.h"
namespace cm{
namespace controllers{
MasterController::MasterController(QObject *parent) : QObject(parent)
{
int i = 1;
i = i +1;
}
}}
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlEngine>
#include <QQmlContext>
#include <controllers/master-controller.h>
int main(int argc, char *argv[])
{
#if defined(Q_OS_WIN)
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
#endif
QGuiApplication app(argc, argv);
qmlRegisterType<cm::controllers::MasterController>("CM",1,0,"MasterController");
cm::controllers::MasterController masterController(NULL);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("masterController",&masterController);
engine.load(QUrl(QStringLiteral("qrc:/views/MasterView.qml")));
if (engine.rootObjects().isEmpty())
return -1;
return app.exec();
}
D:\WORKC\QT\cm\cm-ui\source\main.cpp:18: error: undefined reference to cm::controllers::MasterController::MasterController(QObject*)' D:\WORKC\QT\shadow-builds\cm-ui\debug\main.o:-1: In function
Z15qmlRegisterTypeIN2cm11controllers16MasterControllerEEiPKciiS4_':
C:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtQml\qqml.h:285: error: undefined reference to cm::controllers::MasterController::staticMetaObject' C:\Qt\Qt5.10.0\5.10.0\mingw53_32\include\QtQml\qqml.h:308: error: undefined reference to
cm::controllers::MasterController::staticMetaObject'
......
Upvotes: 0
Views: 535
Reputation: 11
class CMLIBSHARED_EXPORT MasterController : public QObject
when I add CMLIBSHARED_EXPORT
to the class definition,Problem solved!
Upvotes: 1