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. Random "Invalid grouped property access" error
Forum Updated to NodeBB v4.3 + New Features

Random "Invalid grouped property access" error

Scheduled Pinned Locked Moved Solved QML and Qt Quick
12 Posts 3 Posters 2.8k 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.
  • G Offline
    G Offline
    GPBeta
    wrote on 8 Aug 2018, 13:12 last edited by GPBeta 8 Aug 2018, 13:18
    #1

    Hello everyone,
    I got a problem confusing me these days when I try to create my own Button which directly inherits QQuickAbstractButton via C++ .

    First, I create a new C++ class:

    class MyButtonTemplate : public QQuickAbstractButton {
        // class definitions
    };
    

    Register it:

    const char uri[] = "MyModule.Templates";
    
    qmlRegisterModule(uri, 1, 0);
    qmlRegisterType<MyButtonTemplate>(uri, 1, 0, "Button");
    

    Refer it in MyModule:

    import QtQuick 2.11
    import MyModule.Templates 1.0 as T
    
    T.Button {
        // invalid grouped property (icon) access
        icon.width: 18
        icon.height: 18
    }
    

    Then I got a run-time error:

    • QQmlApplicationEngine failed to load component
    • qrc:/main.qml:17 Type My.Button unavailable
    • qrc:///imports/MyModule/Button.qml:10 "T.Button.icon" is not available in MyModule.Templates 1.0.
    • InvalidAccess exited with code -1

    So I register the corresponding revision of QQuickAbstractButton for my module:

    qmlRegisterRevision<QQuickAbstractButton, 4>(uri, 1, 0);
    

    Now, my app runs as expected......sometimes :( The program will have around 50% chances to raise an error:

    • QQmlApplicationEngine failed to load component
    • qrc:/main.qml:15 Type Button unavailable
    • file:///F:/DEV/Library/QT/5.11.0/msvc2015_64/qml/QtQuick/Controls.2/Button.qml:56 Invalid grouped property access
    • InvalidAccess exited with code -1

    Here's my main.qml:

    import QtQuick 2.11
    import QtQuick.Controls 2.4
    import QtQuick.Window 2.11
    
    import MyModule 1.0 as My
    
    Window {
        visible: true
    
        title: "Invalid Access"
    
        Column {
            anchors.centerIn: parent
    
            Button { text: "Qt Button" }
    
            My.Button { text: "My Button" }
        }
    }
    

    If I remove the QtQuick.Controls's Button, program will always raise that error.

    Environment: Windows 10, Qt 5.11 x64
    Here's a minimum demo project:
    https://drive.google.com/file/d/1XCjSXlXu4SfulP_hwRVwkoDjejdComHV/view?usp=sharing

    Is this a bug or something I missed?
    Thank you for any ideas :)

    \BAKA BAKA/

    1 Reply Last reply
    0
    • D Offline
      D Offline
      devDawg
      wrote on 9 Aug 2018, 04:21 last edited by
      #2

      How are you assigning icon? Perhaps you have an undefined property somewhere. Post that code if you have it please.

      But in the mean time, use something like this:

      T.Button {
          Component.onCompleted: {
             
              // check properties here. Nothing should be undefined, unless it's supposed to be.
              //for each property, do something like : 
              
      if (!this_property.isUndefined()) { assign value }    //elegant pseudocode                                  
      
      else { handle undefined value (avoid crash) } //more elegant pseudocode
      
      }
      } 
      
      

      Let me know how this goes.

      Cheers

      Anything worthwhile is never achieved easily.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GPBeta
        wrote on 9 Aug 2018, 07:59 last edited by GPBeta 8 Sept 2018, 08:04
        #3

        @devDawg Thank you for your reply :)
        Please checkout the completed minimal project to reproduce this issue:

        https://drive.google.com/file/d/1XCjSXlXu4SfulP_hwRVwkoDjejdComHV/view?usp=sharing

        There's no other property access will raise this error, except for this revision tagged and grouped icon property which is defined in QQuickAbstractButton.
        The Component.onCompleted() solution is not very suitable for my requirement because it will override bindings created before component completed.

        \BAKA BAKA/

        D 1 Reply Last reply 9 Aug 2018, 10:16
        0
        • G GPBeta
          9 Aug 2018, 07:59

          @devDawg Thank you for your reply :)
          Please checkout the completed minimal project to reproduce this issue:

          https://drive.google.com/file/d/1XCjSXlXu4SfulP_hwRVwkoDjejdComHV/view?usp=sharing

          There's no other property access will raise this error, except for this revision tagged and grouped icon property which is defined in QQuickAbstractButton.
          The Component.onCompleted() solution is not very suitable for my requirement because it will override bindings created before component completed.

          D Offline
          D Offline
          Diracsbracket
          wrote on 9 Aug 2018, 10:16 last edited by Diracsbracket 8 Sept 2018, 10:20
          #4

          Hi @GPBeta
          I tried your example, it works without problems on my system (Win10, VS2017, Qt 5.11.0).
          The "randomness" of the problem seems not reproducible here?

                  My.Button {
                      text: "My Button"
                      onClicked: {
                          console.debug("T.Button: " + icon.height + ", " + icon.width)
                      }
                  }
          

          gives:

          qml: T.Button: 18, 18
          qml: T.Button: 18, 18
          qml: T.Button: 18, 18
          ...
          qml: T.Button: 18, 18
          qml: T.Button: 18, 18
          qml: T.Button: 18, 18
          

          No warnings nor errors are produced.

          1 Reply Last reply
          0
          • G Offline
            G Offline
            GPBeta
            wrote on 9 Aug 2018, 14:02 last edited by GPBeta 8 Sept 2018, 14:03
            #5

            Hi @Diracsbracket
            The error occurs randomly only on startup, so please try to start it as much as possible, or just remove

            Button { text: "Qt Button" }
            

            and the program will never start here.

            \BAKA BAKA/

            D 1 Reply Last reply 9 Aug 2018, 15:18
            0
            • G GPBeta
              9 Aug 2018, 14:02

              Hi @Diracsbracket
              The error occurs randomly only on startup, so please try to start it as much as possible, or just remove

              Button { text: "Qt Button" }
              

              and the program will never start here.

              D Offline
              D Offline
              Diracsbracket
              wrote on 9 Aug 2018, 15:18 last edited by
              #6

              @GPBeta
              What is MyModule.Templates? You import it in imports\MyModule\Button.qml but it's defined nowhere.

              G 1 Reply Last reply 9 Aug 2018, 15:21
              0
              • D Diracsbracket
                9 Aug 2018, 15:18

                @GPBeta
                What is MyModule.Templates? You import it in imports\MyModule\Button.qml but it's defined nowhere.

                G Offline
                G Offline
                GPBeta
                wrote on 9 Aug 2018, 15:21 last edited by
                #7

                @Diracsbracket
                MyModule.Templates is registered via qmlRegisterModule("MyModule.Templates", 1, 0);
                T.Button is registered via qmlRegisterType<MyButtonTemplate>("MyModule.Templates", 1, 0, "Button");
                They're both C++ codes in main.cpp

                \BAKA BAKA/

                D 2 Replies Last reply 9 Aug 2018, 16:09
                0
                • G GPBeta
                  9 Aug 2018, 15:21

                  @Diracsbracket
                  MyModule.Templates is registered via qmlRegisterModule("MyModule.Templates", 1, 0);
                  T.Button is registered via qmlRegisterType<MyButtonTemplate>("MyModule.Templates", 1, 0, "Button");
                  They're both C++ codes in main.cpp

                  D Offline
                  D Offline
                  Diracsbracket
                  wrote on 9 Aug 2018, 16:09 last edited by Diracsbracket 8 Sept 2018, 17:16
                  #8

                  @GPBeta
                  My bad... should have read your post more carefully...
                  I have never defined or even used templates before, so I will just watch and learn from this thread...

                  1 Reply Last reply
                  0
                  • G GPBeta
                    9 Aug 2018, 15:21

                    @Diracsbracket
                    MyModule.Templates is registered via qmlRegisterModule("MyModule.Templates", 1, 0);
                    T.Button is registered via qmlRegisterType<MyButtonTemplate>("MyModule.Templates", 1, 0, "Button");
                    They're both C++ codes in main.cpp

                    D Offline
                    D Offline
                    Diracsbracket
                    wrote on 9 Aug 2018, 16:50 last edited by Diracsbracket 8 Sept 2018, 16:56
                    #9

                    @GPBeta
                    By adding:

                    import QtQuick.Templates 2.2
                    

                    to your Button.qml template file, it seems to work?

                    import QtQuick 2.11
                    import QtQuick.Templates 2.2
                    import MyModule.Templates 1.0 as T
                    

                    Apparently, without it, the required QQuickIcon type from

                    qtquickcontrols2/src/quicktemplates2/qquickicon_p.h
                    

                    does not get registered, hence the errors you get?

                    1 Reply Last reply
                    2
                    • G Offline
                      G Offline
                      GPBeta
                      wrote on 9 Aug 2018, 17:27 last edited by
                      #10

                      @Diracsbracket Great! It works perfectly now!

                      The QQuickIcon is registered in the QtQuick.Templates qml plug-in(qtquicktemplates2plugin.dll), while my C++ module only linked against Qt5QuickTemplates2.dll.

                      So if we don't import that module explicitly, the icon property may be randomly registered later than the binding access.

                      I also tried to add depends QtQuick.Templates 2.4 in the qmldir but with no luck.

                      Whatever, I believe this is the best solution for me, thank you so much :)

                      \BAKA BAKA/

                      D 1 Reply Last reply 10 Aug 2018, 02:11
                      1
                      • G GPBeta
                        9 Aug 2018, 17:27

                        @Diracsbracket Great! It works perfectly now!

                        The QQuickIcon is registered in the QtQuick.Templates qml plug-in(qtquicktemplates2plugin.dll), while my C++ module only linked against Qt5QuickTemplates2.dll.

                        So if we don't import that module explicitly, the icon property may be randomly registered later than the binding access.

                        I also tried to add depends QtQuick.Templates 2.4 in the qmldir but with no luck.

                        Whatever, I believe this is the best solution for me, thank you so much :)

                        D Offline
                        D Offline
                        Diracsbracket
                        wrote on 10 Aug 2018, 02:11 last edited by Diracsbracket 8 Oct 2018, 03:41
                        #11

                        @GPBeta
                        Thank you for the explanation. Now the randomness makes sense.
                        Btw. I just checked your webpage. It's quite awesome!

                        G 1 Reply Last reply 10 Aug 2018, 05:15
                        0
                        • D Diracsbracket
                          10 Aug 2018, 02:11

                          @GPBeta
                          Thank you for the explanation. Now the randomness makes sense.
                          Btw. I just checked your webpage. It's quite awesome!

                          G Offline
                          G Offline
                          GPBeta
                          wrote on 10 Aug 2018, 05:15 last edited by
                          #12

                          @Diracsbracket lol, thank you :P

                          \BAKA BAKA/

                          1 Reply Last reply
                          0

                          1/12

                          8 Aug 2018, 13:12

                          • Login

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