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.

Qt Code:
  1. int main(int argc, char *argv[])
  2. {
  3. QApplication app(argc, argv);
  4.  
  5. QQmlApplicationEngine engine;
  6. engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
  7.  
  8. QObject * object = engine.rootObjects().value(0);
  9.  
  10. QVariant returnedValue;
  11. QVariant msg = "Hello from C++";
  12. QMetaObject::invokeMethod(object, "myQmlFunction",
  13. Q_RETURN_ARG(QVariant, returnedValue),
  14. Q_ARG(QVariant, msg));
  15.  
  16. return app.exec();
  17. }
To copy to clipboard, switch view to plain text mode