Hi,
I started to experiment with this example. Unfortunately I keep getting the following error message:
ReferenceError: myGlobalObject is not defined.
myglobalobject.h:
#ifndef MYGLOBALOBJECT_H
#define MYGLOBALOBJECT_H
#include <QObject>
class MyGlobalObject : public QObject
{
Q_OBJECT
public:
MyGlobalObject();
public slots:
void doSomething(const QString &text);
};
#endif // MYGLOBALOBJECT_H
main.cpp:
#include <QApplication>
#include <VPApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "myglobalobject.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
VPApplication vplay;
vplay.setPreservePlatformFonts(true);
QQmlApplicationEngine engine;
vplay.initialize(&engine);
vplay.setMainQmlFileName(QStringLiteral("qml/Main.qml"));
MyGlobalObject *myGlobal = new MyGlobalObject();
myGlobal->doSomething ("TEXT FROM C++");
engine.rootContext ()->setContextProperty ("myGlobalObject",myGlobal);
engine.load(QUrl(vplay.mainQmlFileName()));
return app.exec();
}
myglobalobject.cpp:
#include "myglobalobject.h"
#include <QDebug>
MyGlobalObject::MyGlobalObject()
{
}
void MyGlobalObject::doSomething(const QString &text)
{
qDebug() << "MyGlobelObject doSomething called with " << text;
}
main.qml:
import Felgo 3.0
import QtQuick 2.0
App {
NavigationStack {
Page {
title: qsTr("Integration")
Column {
AppButton {
text: "MyGlobalObject.doSomething()"
onClicked: myGlobalObject.doSomething("TEXT FROM QML")
}
}
}
}
}
Please tell me what is wrong with my code.
Thank you for your help.