I am trying for Loading Qml From c++ file. How to load qml file from c++ . It is by default loaded from main.cpp file but i want to load it from my class (e.g MyClass => user define class).
My code is here
1) main.cpp
QGuiApplication app(argc, argv);
MyClass tr;
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/App/main.qml"));
viewer.showExpanded();
tr.setApplication(&app,&viewer);
2) MyClass.cpp
setApplication(QGuiApplication *a,QtQuick2ApplicationViewer *v)
{
this->app = app;
this->viewer = viewer;
}
// This loadQmlFile() slot I have called from qml using signal
3) loadQmlFile function
void MyClass::loadQmlFile()
{
// code for changing qml here
viewer->setMainQmlFile(QStringLiteral("qml/App/main.qml"));
}
But program getting crashed. Please help me how to load Qml from c++