Skip to content

Instantly share code, notes, and snippets.

@FONQRI
Created August 29, 2018 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FONQRI/d4456b68936f75e2bd7fcd16734b166d to your computer and use it in GitHub Desktop.
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++
#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