#include#include int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }
class MyObject : public QObject { Q_OBJECT public: Q_INVOKABLE void myMethod() { qDebug() << "My method has been called!"; } }; int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; qmlRegisterTypeThis code registers a C++ type called MyObject with the QML type system. This allows MyObject to be used directly from QML. In this particular example, MyObject has a method called "myMethod" that simply prints a debugging message. Package Library: This example uses the Qt and QtQuick libraries from the Qt package.("MyModule", 1, 0, "MyObject"); engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); return app.exec(); }