Hi,
I use this code in "main.cpp" and that is Ok.
But I do not know How can I use this code in another c++ class.
When I put this code in another class (for example myserialport.cpp), program does not work.
int main(int argc, char *argv[])
{
QQmlApplicationEngine engine;
engine.
load(QUrl(QStringLiteral
("qrc:/main.qml")));
QObject * object
= engine.
rootObjects().
value(0);
return app.exec();
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QQmlApplicationEngine engine;
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
QObject * object = engine.rootObjects().value(0);
QVariant returnedValue;
QVariant msg = "Hello from C++";
QMetaObject::invokeMethod(object, "myQmlFunction",
Q_RETURN_ARG(QVariant, returnedValue),
Q_ARG(QVariant, msg));
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks