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. Interception of required properties within c++
Forum Updated to NodeBB v4.3 + New Features

Interception of required properties within c++

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
9 Posts 3 Posters 554 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.
  • magrifM Offline
    magrifM Offline
    magrif
    wrote on last edited by magrif
    #1

    Hi everyone.
    I have a c++ class MyClass and declaratively instantiate it in QML like:

    MyClass {
        required property int foo
        required property double bar
        required property string baz
    }
    

    There is a way to intercept and initialize this properties at c++ side? Q_PROPERTY is not used.

    GrecKoG 1 Reply Last reply
    0
    • magrifM magrif

      Hi everyone.
      I have a c++ class MyClass and declaratively instantiate it in QML like:

      MyClass {
          required property int foo
          required property double bar
          required property string baz
      }
      

      There is a way to intercept and initialize this properties at c++ side? Q_PROPERTY is not used.

      GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      @magrif you can query its metaObject() and list all its properties. QMetaProperty has a isRequired() method.

      1 Reply Last reply
      1
      • magrifM Offline
        magrifM Offline
        magrif
        wrote on last edited by
        #3

        I know, but application crashes with error about not initialized required properties before I have call QMetaProperty::write.

        GrecKoG TomZT 2 Replies Last reply
        0
        • magrifM magrif

          I know, but application crashes with error about not initialized required properties before I have call QMetaProperty::write.

          GrecKoG Offline
          GrecKoG Offline
          GrecKo
          Qt Champions 2018
          wrote on last edited by
          #4

          How do you instantiate the object?

          1 Reply Last reply
          0
          • magrifM magrif

            I know, but application crashes with error about not initialized required properties before I have call QMetaProperty::write.

            TomZT Offline
            TomZT Offline
            TomZ
            wrote on last edited by
            #5

            @magrif said in Interception of required properties within c++:

            but application crashes with error about not initialized required properties

            That has nothing to do with the C++ part.
            You wrote "required". Which implies you created a new qml file, right?

            Then when someone actually USES that new QML file, they are required to provide those properties.

            Like:

            
            Foo.qml
            Item {
               required property int foo;
            }
            
            Bar.qml
            Item {
                Foo {
                    foo: 1 // required property is provided here!
                }
            }
            
            1 Reply Last reply
            0
            • magrifM Offline
              magrifM Offline
              magrif
              wrote on last edited by
              #6

              @GrecKo said in Interception of required properties within c++:

              How do you instantiate the object?

              @magrif said in Interception of required properties within c++:

              declaratively instantiate it in QML



              @TomZ said in Interception of required properties within c++:

              Then when someone actually USES that new QML file, they are required to provide those properties.

              @magrif said in Interception of required properties within c++:

              There is a way to intercept and initialize this properties at c++ side?

              1 Reply Last reply
              0
              • magrifM Offline
                magrifM Offline
                magrif
                wrote on last edited by magrif
                #7

                I mean set values somewhere inside MyClass. May be some private interfaces or like QQmlParserStatus.

                GrecKoG 1 Reply Last reply
                0
                • magrifM magrif

                  I mean set values somewhere inside MyClass. May be some private interfaces or like QQmlParserStatus.

                  GrecKoG Offline
                  GrecKoG Offline
                  GrecKo
                  Qt Champions 2018
                  wrote on last edited by
                  #8

                  @magrif Sorry I misiread.

                  Why do you need the properties to be required?

                  1 Reply Last reply
                  0
                  • magrifM Offline
                    magrifM Offline
                    magrif
                    wrote on last edited by magrif
                    #9

                    @GrecKo No problem. I want make object with shared properties. For instance in one part of application create:

                    MyClass {
                        property int foo: 100
                        roperty double bar: 500.0
                        property string baz: "Hello"
                    }
                    

                    The values of properties will be saved inside a c++-side data structure, details here doesn't matter. And somewhere else initialize them to eponymous properties, if they marked as required:

                    MyClass {
                        required property int foo
                        required property double bar
                        required property string baz
                    }
                    

                    I would be use and without required keyword, just see if property have value or not. And just initialize it by shared value if no have one . But for primitive types (bool, int) its respectivelyQVariant(bool, false)/QVariant(int, 0) rather than QVariant(Invalid) .

                    So I'm trying figure out how it works inside Qt.

                    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