Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. How to add "property alias" only for testing at "QML" file.
Forum Updated to NodeBB v4.3 + New Features

How to add "property alias" only for testing at "QML" file.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 403 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dmhk_4ss
    wrote on last edited by
    #1

    I want to add "property alias" only for testing at QML file.
    Is there any way to do it ?

    //sample.qml
    
    Item {
    
        // I want to these properties for testing only.
        property alias innerListView: idListView
        property alias currentItem: idListView.currentItem
    
        ListView {
            id: idListView
            anchors.fill: parent
            clip: true
            model: weekModel
            delegate: Component
            {
                id: weekDelegate
                Item {
                    id: delegateItem
                    property alias text: menuText.text
                    
                    Text {
                        id :menuText
                        text: modelData
                    }
                }
            }
        }
        ListModel {
            id: weekModel
            ListElement{day: "Sunday"}
            ListElement{day: "Monday"}
            ListElement{day: "Tuesday"}
            ListElement{day: "Wednesday"}
            ListElement{day: "Thursday"}
            ListElement{day: "Saturday"}
        }
    }
    

    Is there any way to do like this ?

    //Rough idea
    
    #ifdef TEST
         property alias innerListView: idListView
    #endif
    
    J.HilkJ 1 Reply Last reply
    1
    • D dmhk_4ss

      I want to add "property alias" only for testing at QML file.
      Is there any way to do it ?

      //sample.qml
      
      Item {
      
          // I want to these properties for testing only.
          property alias innerListView: idListView
          property alias currentItem: idListView.currentItem
      
          ListView {
              id: idListView
              anchors.fill: parent
              clip: true
              model: weekModel
              delegate: Component
              {
                  id: weekDelegate
                  Item {
                      id: delegateItem
                      property alias text: menuText.text
                      
                      Text {
                          id :menuText
                          text: modelData
                      }
                  }
              }
          }
          ListModel {
              id: weekModel
              ListElement{day: "Sunday"}
              ListElement{day: "Monday"}
              ListElement{day: "Tuesday"}
              ListElement{day: "Wednesday"}
              ListElement{day: "Thursday"}
              ListElement{day: "Saturday"}
          }
      }
      

      Is there any way to do like this ?

      //Rough idea
      
      #ifdef TEST
           property alias innerListView: idListView
      #endif
      
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      hi @dmhk_4ss and welcome

      something like this could be done.

      Inside your main set a property depending on specific circumstances, in this example, debug or not debug

          QQmlApplicationEngine engine;
      #ifdef QT_DEBUG
          engine.rootContext()->setContextProperty("debug", true);
      #else
          engine.rootContext()->setContextProperty("debug", false);
      #endif
      
      property var innerListView:  debug ? idListView : undefined //can't assign undefined to an alias -> var
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      3
      • D Offline
        D Offline
        dmhk_4ss
        wrote on last edited by
        #3

        Hi @J-Hilk san

        It is a great idea !
        Thank you very much.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved