[SOLVED]Reference from QT is not found in QML / Multiple QML file Communication with QT



  • Hi,
    Is the below code valid !!!

    the issue is im getting an error from QML page--- the reference error :"mainSettings" is not defined.
    but I have defined it. rest every thing is working fine.

    @ QGuiApplication app(argc, argv);
    GUIHandler libSetup;
    settingsPage settings;

    QtQuick2ApplicationViewer viewer;
    QtQuick2ApplicationViewer settingsviewer;
    
    viewer.rootContext()->setContextProperty("libSetup",&libSetup);
    viewer.setMainQmlFile(QStringLiteral("qml/Test1/main.qml"));
    
    settingsviewer.rootContext()->setContextProperty("mainSettings",&settings);
    settingsviewer.setSource(QStringLiteral("qml/Test1/Settings.qml"));
    
    viewer.showFullScreen();@
    

    Im not sure if this helps --- main.qml contains settings component(Settings.qml) in it.

    Please help.


  • Lifetime Qt Champion

    Hi,

    Valid yes, but doesn't work like you think.

    Why are you using two different viewers ? mainSettings is only valid in the context of settingsviewer not in viewer.



  • Oh,
    Sorry I'nt knew that.
    The reason i wanted to use is, I have to call qt function from settings and even I have some properties where settings.qml uses.

    @ boxes.children[i].txtLabel=mainSettings.readBedNoSetup(i+1)@

    and im sending this data to qt for saving in an ini file.

    even this goes same with main.qml but it has its own properties declared in other class.

    So,
    is there any other way to handle it.?
    i just need to make settings.qml to talk with qt's (Q_INVOKABLE) methods



  • @
    QQmlEngine engine;
    engine.rootContext()->setContextProperty("mainSettings",&setting);
    QQmlComponent component(&engine, QUrl::fromLocalFile("qml/Test1/Settings.qml"));
    component.create();@

    Even this did not work.

    Hope I need to go to docs again.
    Mean while, If there is any way please let me know



  • Hi,
    Finally I went through the docs and googled all possible ways and solved the issue.
    Thanks for the Docs provided by QT team.

    The way I solved is by using

    1. Signal-Slot communication b/w QML and QT.
    2. Sharing data b/w QML files with the help of Java Scripts.
    3. inter function accessing b/w QML files.

    when through these docs
    "QML bindings":http://qt-project.org/doc/qt-5/qtqml-cppintegration-interactqmlfromcpp.html#connecting-to-qml-signals

    "QML Signals":http://qt-project.org/doc/qt-4.8/qmlevents.html

    "Extending QML":http://qt-project.org/doc/qt-4.8/qtbinding.html#javascript-arrays-and-objects


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.