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. declare property of pointer in qml

declare property of pointer in qml

Scheduled Pinned Locked Moved QML and Qt Quick
property
15 Posts 3 Posters 7.1k 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.
  • T Offline
    T Offline
    themts
    wrote on 1 Apr 2015, 09:55 last edited by themts 4 Jan 2015, 09:55
    #5

    ok, I think it's not clear what I want.

    • I have a list with many objects in it (qList<ClassNameOfModel*>).
    • I display the list with a combobox (list is assigned as model to combobox)
    • I select one item in that combobox

    until here, no problem.

    Now I want to pass the selected item (ClassNameOfModel) to my common edit-component (qml-file) to display and edit some item-properties.
    This common edit-component looks like this:

    editComponent.qml:
    Item {
        property ClassNameOfModel *dataModel << This doesn't work
        TextField {
            text: dataModel.text1
            ...
        }
        TextField {
            text: dataModel.text2
            ...
        }
        TextField {
            text: dataModel.text3
            ...
        }
       ...
    }
    

    How can I pass data to my custom-component?

    P 1 Reply Last reply 1 Apr 2015, 10:08
    0
    • T themts
      1 Apr 2015, 09:55

      ok, I think it's not clear what I want.

      • I have a list with many objects in it (qList<ClassNameOfModel*>).
      • I display the list with a combobox (list is assigned as model to combobox)
      • I select one item in that combobox

      until here, no problem.

      Now I want to pass the selected item (ClassNameOfModel) to my common edit-component (qml-file) to display and edit some item-properties.
      This common edit-component looks like this:

      editComponent.qml:
      Item {
          property ClassNameOfModel *dataModel << This doesn't work
          TextField {
              text: dataModel.text1
              ...
          }
          TextField {
              text: dataModel.text2
              ...
          }
          TextField {
              text: dataModel.text3
              ...
          }
         ...
      }
      

      How can I pass data to my custom-component?

      P Offline
      P Offline
      p3c0
      Moderators
      wrote on 1 Apr 2015, 10:08 last edited by
      #6

      @themts Ok how do you call or load editComponent.qml ?

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        themts
        wrote on 1 Apr 2015, 10:40 last edited by
        #7

        ???

        editComponent {
        id: edit1
        }
        

        My idea was to use onCurrentIndexChanged to assign the selected model to my editComponent:

            configComboBox.onCurrentIndexChanged: {
                edit.dataModel: configComboBox.model[configComboBox.currentIndex]
            }
        
        P 1 Reply Last reply 1 Apr 2015, 10:46
        0
        • T themts
          1 Apr 2015, 10:40

          ???

          editComponent {
          id: edit1
          }
          

          My idea was to use onCurrentIndexChanged to assign the selected model to my editComponent:

              configComboBox.onCurrentIndexChanged: {
                  edit.dataModel: configComboBox.model[configComboBox.currentIndex]
              }
          
          P Offline
          P Offline
          p3c0
          Moderators
          wrote on 1 Apr 2015, 10:46 last edited by
          #8

          @themts AFAIK you can do this

          property ClassNameOfModel dataModel
          

          Have done something similar but with Rectangle.
          What error do you get if you do it ?

          157

          1 Reply Last reply
          0
          • T Offline
            T Offline
            themts
            wrote on 1 Apr 2015, 10:51 last edited by
            #9

            This declaration would create an instance of ClassNameOfModel.

            P 1 Reply Last reply 1 Apr 2015, 10:56
            0
            • T themts
              1 Apr 2015, 10:51

              This declaration would create an instance of ClassNameOfModel.

              P Offline
              P Offline
              p3c0
              Moderators
              wrote on 1 Apr 2015, 10:56 last edited by
              #10

              @themts I guess no. You can check it by printing dataModel. It should be null.

              157

              1 Reply Last reply
              0
              • T Offline
                T Offline
                themts
                wrote on 1 Apr 2015, 12:08 last edited by
                #11

                @themts:
                It doesn't work.
                I register my dataModelClass like this:
                qmlRegisterUncreatableType<ClassNameOfModel>("com.test.application", 1, 0, "ClassNameOfModel", "no no no");
                As soon as I start my application I see the output:

                ...
                qrc:/ConfigEdit.qml:3 Type ConfigEditEditForm unavailable
                qrc:/ConfigEditEditForm.ui.qml:6 no no no
                
                P B 2 Replies Last reply 1 Apr 2015, 12:24
                0
                • T themts
                  1 Apr 2015, 12:08

                  @themts:
                  It doesn't work.
                  I register my dataModelClass like this:
                  qmlRegisterUncreatableType<ClassNameOfModel>("com.test.application", 1, 0, "ClassNameOfModel", "no no no");
                  As soon as I start my application I see the output:

                  ...
                  qrc:/ConfigEdit.qml:3 Type ConfigEditEditForm unavailable
                  qrc:/ConfigEditEditForm.ui.qml:6 no no no
                  
                  P Offline
                  P Offline
                  p3c0
                  Moderators
                  wrote on 1 Apr 2015, 12:24 last edited by
                  #12

                  @themts Can you post the complete compilable example ? Getting confused now O.o

                  157

                  1 Reply Last reply
                  0
                  • T themts
                    1 Apr 2015, 12:08

                    @themts:
                    It doesn't work.
                    I register my dataModelClass like this:
                    qmlRegisterUncreatableType<ClassNameOfModel>("com.test.application", 1, 0, "ClassNameOfModel", "no no no");
                    As soon as I start my application I see the output:

                    ...
                    qrc:/ConfigEdit.qml:3 Type ConfigEditEditForm unavailable
                    qrc:/ConfigEditEditForm.ui.qml:6 no no no
                    
                    B Offline
                    B Offline
                    Buttink
                    wrote on 1 Apr 2015, 13:31 last edited by
                    #13

                    @themts This is a known problem with registering an uncreateable type. Its because QML is declarative. See this ticket https://bugreports.qt.io/browse/QTBUG-36752?jql=text ~ "Uncreatable C%2B%2B type can't be used for QML property types" . You have to just do QmlRegisterType<>. If you read the docs for qmlRegisterUncreatableType it says "This is useful where the type is only intended for providing attached properties or enum values.".

                    1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      themts
                      wrote on 1 Apr 2015, 13:39 last edited by themts 4 Jan 2015, 13:41
                      #14

                      @Buttink:
                      I already tried qmlRegisterType<ClassNameOfModel>() but then I get the message:
                      ClassNameOfModel is not a type

                      A workaround for me was now to declare a generic property var.
                      This way I have no code-completition but it works. Of course I would prefer a typesafe way.

                      I think it only works if I register the class as a creatable object, but then I have to implement a copyconstructor etc.

                      B 1 Reply Last reply 1 Apr 2015, 14:02
                      0
                      • T themts
                        1 Apr 2015, 13:39

                        @Buttink:
                        I already tried qmlRegisterType<ClassNameOfModel>() but then I get the message:
                        ClassNameOfModel is not a type

                        A workaround for me was now to declare a generic property var.
                        This way I have no code-completition but it works. Of course I would prefer a typesafe way.

                        I think it only works if I register the class as a creatable object, but then I have to implement a copyconstructor etc.

                        B Offline
                        B Offline
                        Buttink
                        wrote on 1 Apr 2015, 14:02 last edited by
                        #15

                        @themts Hmmm that sounds really odd, but without the code, I don't know why it would output that error. I will say that you do not need a copy constructor. You could make a new qml type from

                        class Thing : public QObject
                        {
                            Q_OBJECT
                        public:
                            explicit Thing(QObject* parent = nullptr);
                            virtual ~Thing();
                        };
                        
                        1 Reply Last reply
                        0

                        14/15

                        1 Apr 2015, 13:39

                        • Login

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