One more quick question. CGuideMenu is derived from QObject and has Q_OBJECT in header but I still get the following error
main.obj:-1: error: LNK2001: unresolved external symbol “public: virtual struct QMetaObject const * __thiscall CGuideMenu::metaObject(void)const “ (?metaObject@CGuideMenu@@UBEPBUQMetaObject@@XZ)
for main.obj
main.cpp
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QObject>
#include <QUrl>
#include <QQuickView>
#include <QQuickItem>
#include <QQmlContext>
#include <QVariant>
#include "guidemenu.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
qmlRegisterType<CGuideMenu>("CGuideMenu", 1, 0, "CGuideMenu");
QQuickView viewer;
CGuideMenu *cMenu = new CGuideMenu(&viewer);
// With that below you can call myMenu.getDisplayString() in QML
//?? neither lines compile????
viewer.rootContext()->setContextProperty("myMenu", QVariant::fromValue(cMenu));
viewer.rootContext()->setContextProperty("myMenu", cMenu);
viewer.setSource(QUrl::fromLocalFile("main.qml"));
viewer.show();
// QQuickItem *window = viewer.rootObject();
// window->setProperty("heading", "BOOH");
return app.exec();
}
guidemenu.h
#ifndef GUIDEMENU_H
#define GUIDEMENU_H
#include <QObject>
class CGuideMenu : public QObject
{
Q_OBJECT
public:
CGuideMenu(QObject *parent = 0);
};
#endif // GUIDEMENU_H
cpp
#include "guidemenu.h"
CGuideMenu::CGuideMenu(QObject *parent) : QObject(parent)
{
parent = parent;
}
pro
# Add more folders to ship with the application, here
folder_01.source = qml/GuideNext
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01
QT += core qml quick
# Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
# If your application uses the Qt Mobility libraries, uncomment the following
# lines and add the respective components to the MOBILITY variable.
# CONFIG += mobility
# MOBILITY +=
# The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp guidemenu.cpp
# Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()
HEADERS += guidemenu.h
↧