neda
8th March 2016, 10:18
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[])
{
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();
}
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[])
{
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();
}