Created
August 29, 2018 15:14
-
-
Save FONQRI/d4456b68936f75e2bd7fcd16734b166d to your computer and use it in GitHub Desktop.
this is a simple example to show how send an object to qml from a QObject based calss in c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QGuiApplication> | |
#include <QQmlApplicationEngine> | |
#include <QtQml/QQmlContext> | |
#include "YourClass.h" | |
int main(int argc, char *argv[]) | |
{ | |
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); | |
QGuiApplication app(argc, argv); | |
QQmlApplicationEngine engine; | |
QQmlContext* context = engine.rootContext(); | |
YourClass yourObject; | |
context->setContextProperty("yourQmlObject",&yourObject); | |
QQmlApplicationEngine engine; | |
engine.load(QUrl(QLatin1String("qrc:/main.qml"))); | |
if (engine.rootObjects().isEmpty()) | |
return -1; | |
return app.exec(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment