2

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++

Ilya
  • 5,377
  • 2
  • 18
  • 33
Tushar
  • 21
  • 2
  • 1
    Similar to this ? http://stackoverflow.com/q/35487237/5695504 – Ilya Feb 23 '16 at 09:01
  • Tushar, welcome to Stackoverflow! Please, give us Minimal, Complete, and Verifiable application (as in http://stackoverflow.com/help/mcve), so we can help you. – NG_ Feb 23 '16 at 10:38
  • its minimal,complete and verifiable application. I did not get what you want more in that? simple i call MyClass::setApplication(QGuiApplication *a,QtQuick2ApplicationViewer *v) from main.cpp and loading main.qml again in MyClass::loadQmlFile() function. but program crashes means terminate. – Tushar Mar 07 '16 at 09:44
  • Not similar llya . Its different. – Tushar Mar 07 '16 at 09:46

0 Answers0