Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Rules for accessing QML properties?



  • Are there any special rules that apply for accessing properties in a QML file from another QML file?

    I've been going around in circles for the last two days trying to figure out why one QML file cannot see a property from another.

    For example I have two QML files:

    ModeSelection.qml
    ModePreview.qml
    

    ModeSelection contains a boolean property defined as follows:

    import QtQuick 2.7
    import QtQuick.Controls 2.1
    import QtGraphicalEffects 1.0
    import ModePreviewManager 1.0
    import "../Utils"
    import MerlinStyle 1.0
    
    Rectangle {
        id: root
        property bool forceHightlight: false
    ...
    

    There is quite a lot more to it, then this is referenced by ModeDetals.qml

    import QtQuick 2.7
    import QtQuick.Controls 2.1
    import QtQuick.Controls.Styles 1.4
    import QtQuick.Layouts 1.3
    import QtGraphicalEffects 1.0
    import ModePreviewManager 1.0
    import "../Utils"
    import "../Utils/imagepaths.js" as ImagePaths
    import "../Style" as Merlin
    import MerlinStyle 1.0
    
    Item {
        /* Properties */
        Item {
            id: modeSelectionArea
    
          ModeSelection {
            id: localMode
            ....
          }
         ModeSelection {
            id: machineMode
            ...
        }
       Connections {
           target: modeSelectionArea
           onRefreshHighlight: {
               joiner.visible = (ModeSelection.forceHightlight == true)
           }
      }
    ...
    

    The use of ModeSelection in the QML to define objects if ok, but in script ModeSelection is not defined and I can see that in the debugger, also an error is displayed in the Application Output that ModeSelection is undefined.

    What is going wrong or what needs to be done?



  • You have to reference it using the instance id and not the component name so it becomeslocalMode.forceHighlight.



  • You have to reference it using the instance id and not the component name so it becomeslocalMode.forceHighlight.



  • @Jkimmy , thank you, I realised this about an hour after I posted, thanks again.


Log in to reply