Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Regarding the exposing of the properties using Q_Property
Forum Updated to NodeBB v4.3 + New Features

Regarding the exposing of the properties using Q_Property

Scheduled Pinned Locked Moved Unsolved General and Desktop
39 Posts 4 Posters 12.3k Views 4 Watching
  • 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.
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by kshegunov
    #2

    Hi,
    You can expose whatever you desire as long as it can be packed in a QVariant, which means it's a declared meta-type (see. Q_DECLARE_METATYPE). There are no other limitations to my knowledge. However, all QObject subclasses (like QLineEdit) can't be returned by value, but by address (as pointers). Same goes for the properties - you can store only QObject * in the variant, thus your class that derive from QObject can only be exposed (in the sense of QObject::property() and QObject::setProperty) through a pointer to the object.

    Kind regards.

    Read and abide by the Qt Code of Conduct

    1 Reply Last reply
    2
    • Pradeep KumarP Offline
      Pradeep KumarP Offline
      Pradeep Kumar
      wrote on last edited by Pradeep Kumar
      #3

      Hi,

      Thanks for the reply . Can u provide a example for understanding , with respect to QSpinBox or QComboBox

      Will be needfull.

      Thanks,

      Pradeep Kumar
      Qt,QML Developer

      kshegunovK 1 Reply Last reply
      0
      • VRoninV Offline
        VRoninV Offline
        VRonin
        wrote on last edited by
        #4

        it's harder to explain than to do. in practice you just need to pass by pointer: instead of Q_PROPERTY(QLineEdit lineEdit,... use Q_PROPERTY(QLineEdit* lineEdit,...

        "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
        ~Napoleon Bonaparte

        On a crusade to banish setIndexWidget() from the holy land of Qt

        1 Reply Last reply
        3
        • Pradeep KumarP Pradeep Kumar

          Hi,

          Thanks for the reply . Can u provide a example for understanding , with respect to QSpinBox or QComboBox

          Will be needfull.

          Thanks,

          kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #5

          Exactly what @VRonin said. There's nothing to it, you only need to use pointers when dealing with QObject subclasses. If you get stuck in a specific case, still, don't hesitate to ask.

          Read and abide by the Qt Code of Conduct

          1 Reply Last reply
          0
          • Pradeep KumarP Offline
            Pradeep KumarP Offline
            Pradeep Kumar
            wrote on last edited by
            #6

            Hi,

            I have done some changes and here is he code.

            setters and getters mothod

            Declaration:

            QLineEdit m_lineEditValue;

            void setLineeditValue(QLineEdit &refValue);
            QLineEdit *getLineEditValue();
            

            Definition:

            void MyWidget::setLineeditValue(QLineEdit &refValue)
            {
            m_lineEditValue = refValue;
            }

            QLineEdit *MyWidget::getLineEditValue()
            {
            return &m_lineEditValue;
            }

            Q_PROPERTY macro to expose the object

            Q_PROPERTY(QLineEdit *getlineEditValue READ getLineEditValue WRITE setLineeditValue DESIGNABLE true)
            

            I am getting the below mentioned error, link is provided.

            https://postimg.org/image/u4zzjfmz1/

            Is it because of the DISABLE copy of assignment operator and how can i expose QLineEdit?.

            Thanks,

            Pradeep Kumar
            Qt,QML Developer

            kshegunovK 1 Reply Last reply
            0
            • Pradeep KumarP Pradeep Kumar

              Hi,

              I have done some changes and here is he code.

              setters and getters mothod

              Declaration:

              QLineEdit m_lineEditValue;

              void setLineeditValue(QLineEdit &refValue);
              QLineEdit *getLineEditValue();
              

              Definition:

              void MyWidget::setLineeditValue(QLineEdit &refValue)
              {
              m_lineEditValue = refValue;
              }

              QLineEdit *MyWidget::getLineEditValue()
              {
              return &m_lineEditValue;
              }

              Q_PROPERTY macro to expose the object

              Q_PROPERTY(QLineEdit *getlineEditValue READ getLineEditValue WRITE setLineeditValue DESIGNABLE true)
              

              I am getting the below mentioned error, link is provided.

              https://postimg.org/image/u4zzjfmz1/

              Is it because of the DISABLE copy of assignment operator and how can i expose QLineEdit?.

              Thanks,

              kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #7

              The problem is you're trying to assign reference to an object (which basically means calling the copy constructor, which is not allowed on QObject subclasses). It should go like this:

              class MyClass : public QObject
              {
              public:
                  Q_OBJECT
                  Q_PROPERTY(QLineEdit * lineEditValue READ lineEditValue WRITE setLineEditValue)
              
                  void setLineEditValue(QLineEdit * value)
                  {
                      m_lineEditValue = value;
                  }
              
                  QLineEdit * lineEditValue() const
                  {
                      return m_lineEditValue;
                  }
              
              private:
                  QLineEdit * m_lineEditValue;
              };
              

              Kind regards.

              Read and abide by the Qt Code of Conduct

              Pradeep KumarP 1 Reply Last reply
              2
              • Pradeep KumarP Offline
                Pradeep KumarP Offline
                Pradeep Kumar
                wrote on last edited by Pradeep Kumar
                #8

                Hi,

                The following code is compiling but the QLineEdit is not getting exposed to property editor,
                i even used DESIGNABLE true .

                I have the class inherited from QWidget.

                QLineEdit *m_lineEditValue;
                

                void MyWidget::setLineeditValue(QLineEdit *refValue)
                {
                m_lineEditValue = refValue;
                }

                QLineEdit *MyWidget::getLineEditValue()
                {
                return m_lineEditValue;
                }

                Q_PROPERTY(QLineEdit *getlineEditValue READ getLineEditValue WRITE setLineeditValue)

                What may be the issue?.

                Thanks,

                Pradeep Kumar
                Qt,QML Developer

                1 Reply Last reply
                0
                • Pradeep KumarP Offline
                  Pradeep KumarP Offline
                  Pradeep Kumar
                  wrote on last edited by
                  #9

                  Hi,

                  As i want to expose properties i require the objects like QLinedit,QComboBox.

                  Link is provided below.
                  https://postimg.org/image/iusdou5dz/

                  i want the button which i marked in red similar in Qt, how can i achieve that?.

                  Thanks,

                  Pradeep Kumar
                  Qt,QML Developer

                  kshegunovK 1 Reply Last reply
                  0
                  • Pradeep KumarP Pradeep Kumar

                    Hi,

                    As i want to expose properties i require the objects like QLinedit,QComboBox.

                    Link is provided below.
                    https://postimg.org/image/iusdou5dz/

                    i want the button which i marked in red similar in Qt, how can i achieve that?.

                    Thanks,

                    kshegunovK Offline
                    kshegunovK Offline
                    kshegunov
                    Moderators
                    wrote on last edited by
                    #10

                    @Pradeep-Kumar said in Regarding the exposing of the properties using Q_Property:

                    i want the button which i marked in red similar in Qt, how can i achieve that?.

                    You want these properties to be available in designer? If I'm not mistaken, the only way to do that is to write a designer plugin, so the problem is not with exposing the properties of the objects per se.

                    Read and abide by the Qt Code of Conduct

                    1 Reply Last reply
                    1
                    • Pradeep KumarP Offline
                      Pradeep KumarP Offline
                      Pradeep Kumar
                      wrote on last edited by
                      #11

                      Hi,

                      I want the properties of ComboBox and ToolButton in Property editor of another client , i am integrating the Qt with another client so, i tried the above mentioned answer of QLineEdit and tried for QComboBox, it didnt expose, should i use designer plugin and how?.

                      Thanks,

                      Pradeep Kumar
                      Qt,QML Developer

                      kshegunovK 1 Reply Last reply
                      0
                      • Pradeep KumarP Pradeep Kumar

                        Hi,

                        I want the properties of ComboBox and ToolButton in Property editor of another client , i am integrating the Qt with another client so, i tried the above mentioned answer of QLineEdit and tried for QComboBox, it didnt expose, should i use designer plugin and how?.

                        Thanks,

                        kshegunovK Offline
                        kshegunovK Offline
                        kshegunov
                        Moderators
                        wrote on last edited by
                        #12

                        @Pradeep-Kumar said in Regarding the exposing of the properties using Q_Property:

                        it didnt expose

                        How do you discern that? To "expose" a property means that it's available through the QObject::setProperty and QObject::property methods by name. There's no other automation put in place for you out of the box (you even need to cast the QVariant you get from those manually), so if you're after a property editor you need to code that yourself.

                        @Pradeep-Kumar said in Regarding the exposing of the properties using Q_Property:

                        should i use designer plugin and how?.

                        I have no idea what that other editor is, but as I said you need to use a designer plugin only if you intend to make your code available to designer. As for other property editors, you have to look up their documentation to discover how they handle object properties, and how to integrate Qt with them.

                        Read and abide by the Qt Code of Conduct

                        1 Reply Last reply
                        0
                        • Pradeep KumarP Offline
                          Pradeep KumarP Offline
                          Pradeep Kumar
                          wrote on last edited by
                          #13

                          Hi,

                          Thanks for the reply.
                          will look into the property editor documentation of other software and then design the code

                          Designer Plugin is only for Qt designer?.

                          Thanks,

                          Pradeep Kumar
                          Qt,QML Developer

                          kshegunovK 1 Reply Last reply
                          0
                          • Pradeep KumarP Pradeep Kumar

                            Hi,

                            Thanks for the reply.
                            will look into the property editor documentation of other software and then design the code

                            Designer Plugin is only for Qt designer?.

                            Thanks,

                            kshegunovK Offline
                            kshegunovK Offline
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #14

                            @Pradeep-Kumar said in Regarding the exposing of the properties using Q_Property:

                            Designer Plugin is only for Qt designer?.

                            Yes. QtCreator uses plugins for different functionality (it's basically one big plugin loader). So you need to provide a designer plugin only if you intend to integrate your code in the designer itself.

                            Read and abide by the Qt Code of Conduct

                            1 Reply Last reply
                            0
                            • kshegunovK kshegunov

                              The problem is you're trying to assign reference to an object (which basically means calling the copy constructor, which is not allowed on QObject subclasses). It should go like this:

                              class MyClass : public QObject
                              {
                              public:
                                  Q_OBJECT
                                  Q_PROPERTY(QLineEdit * lineEditValue READ lineEditValue WRITE setLineEditValue)
                              
                                  void setLineEditValue(QLineEdit * value)
                                  {
                                      m_lineEditValue = value;
                                  }
                              
                                  QLineEdit * lineEditValue() const
                                  {
                                      return m_lineEditValue;
                                  }
                              
                              private:
                                  QLineEdit * m_lineEditValue;
                              };
                              

                              Kind regards.

                              Pradeep KumarP Offline
                              Pradeep KumarP Offline
                              Pradeep Kumar
                              wrote on last edited by
                              #15

                              @kshegunov said in Regarding the exposing of the properties using Q_Property:

                              The problem is you're trying to assign reference to an object (which basically means calling the copy constructor, which is not allowed on QObject subclasses). It should go like this:

                              class MyClass : public QObject
                              {
                              public:
                                  Q_OBJECT
                                  Q_PROPERTY(QLineEdit * lineEditValue READ lineEditValue WRITE setLineEditValue)
                              
                                  void setLineEditValue(QLineEdit * value)
                                  {
                                      m_lineEditValue = value;
                                  }
                              
                                  QLineEdit * lineEditValue() const
                                  {
                                      return m_lineEditValue;
                                  }
                              
                              private:
                                  QLineEdit * m_lineEditValue;
                              };
                              

                              Can u explain what will be the scenario if we try to send the reference in Q_PROPERTY.
                              like QLineEdit,QComboBox etc.

                              Thanks,

                              Pradeep Kumar
                              Qt,QML Developer

                              kshegunovK 1 Reply Last reply
                              0
                              • Pradeep KumarP Pradeep Kumar

                                @kshegunov said in Regarding the exposing of the properties using Q_Property:

                                The problem is you're trying to assign reference to an object (which basically means calling the copy constructor, which is not allowed on QObject subclasses). It should go like this:

                                class MyClass : public QObject
                                {
                                public:
                                    Q_OBJECT
                                    Q_PROPERTY(QLineEdit * lineEditValue READ lineEditValue WRITE setLineEditValue)
                                
                                    void setLineEditValue(QLineEdit * value)
                                    {
                                        m_lineEditValue = value;
                                    }
                                
                                    QLineEdit * lineEditValue() const
                                    {
                                        return m_lineEditValue;
                                    }
                                
                                private:
                                    QLineEdit * m_lineEditValue;
                                };
                                

                                Can u explain what will be the scenario if we try to send the reference in Q_PROPERTY.
                                like QLineEdit,QComboBox etc.

                                Thanks,

                                kshegunovK Offline
                                kshegunovK Offline
                                kshegunov
                                Moderators
                                wrote on last edited by kshegunov
                                #16

                                @Pradeep-Kumar said in Regarding the exposing of the properties using Q_Property:

                                Can u explain what will be the scenario if we try to send the reference in Q_PROPERTY.

                                You can't. References can't be assigned, meaning this is ill formed:

                                AnyClass & ref;
                                AnyClass object;
                                
                                ref = object; //< Wrong! Not allowed. (C++)
                                

                                You also can't pass those objects by value, because QObject doesn't allow copying. The following is wrong too:

                                QObject a, b;
                                a = b; //< Wrong! Not allowed. (Qt)
                                

                                You're pretty much stuck to using pointers.

                                Read and abide by the Qt Code of Conduct

                                1 Reply Last reply
                                1
                                • Pradeep KumarP Offline
                                  Pradeep KumarP Offline
                                  Pradeep Kumar
                                  wrote on last edited by
                                  #17

                                  k,

                                  can u explain what will be the result of the code which u helped me to go through with having below.

                                  class MyClass : public QObject
                                  {
                                  public:
                                      Q_OBJECT
                                      Q_PROPERTY(QLineEdit * lineEditValue READ lineEditValue WRITE setLineEditValue)
                                  
                                      void setLineEditValue(QLineEdit * value)
                                      {
                                          m_lineEditValue = value;
                                      }
                                  
                                      QLineEdit * lineEditValue() const
                                      {
                                          return m_lineEditValue;
                                      }
                                  
                                  private:
                                      QLineEdit * m_lineEditValue;
                                  };
                                  

                                  Thanks,

                                  Pradeep Kumar
                                  Qt,QML Developer

                                  1 Reply Last reply
                                  0
                                  • Pradeep KumarP Offline
                                    Pradeep KumarP Offline
                                    Pradeep Kumar
                                    wrote on last edited by
                                    #18

                                    Hi,

                                    I am using the

                                    Q_PROPERTY( QBrush brush READ getBrush WRITE setBrush DESIGNABLE true)
                                    to expose property to the property editor of client (not Qt designer.)

                                    How the toolbutton is present can anyone explain, how the tolbutton is provided at the end of the property?.
                                    Is this the custom widget implemented or Qt has provided the toobutton for QBrush?.

                                    @mrjj

                                    as u have also had hands on WinCC OA, can u provide guidance?.

                                    Thanks,

                                    Pradeep Kumar
                                    Qt,QML Developer

                                    mrjjM 1 Reply Last reply
                                    0
                                    • Pradeep KumarP Pradeep Kumar

                                      Hi,

                                      I am using the

                                      Q_PROPERTY( QBrush brush READ getBrush WRITE setBrush DESIGNABLE true)
                                      to expose property to the property editor of client (not Qt designer.)

                                      How the toolbutton is present can anyone explain, how the tolbutton is provided at the end of the property?.
                                      Is this the custom widget implemented or Qt has provided the toobutton for QBrush?.

                                      @mrjj

                                      as u have also had hands on WinCC OA, can u provide guidance?.

                                      Thanks,

                                      mrjjM Offline
                                      mrjjM Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #19

                                      @Pradeep-Kumar
                                      Hi
                                      Sadly I have never tried integrated anyting in the winCC editor.
                                      So it seems its made in Qt also ? only way it could ever understand
                                      a Qt property.

                                      "How the toolbutton is present can anyone explain, how the tolbutton is provided at the end of the property?."

                                      Im sorry , but Im not understanding what you are asking.
                                      This is just a brush so there is no button there.

                                      Can you show some pictures ( of what you mean/have)
                                      and may a ref to the doc of
                                      integration. ?

                                      1 Reply Last reply
                                      1
                                      • Pradeep KumarP Offline
                                        Pradeep KumarP Offline
                                        Pradeep Kumar
                                        wrote on last edited by Pradeep Kumar
                                        #20

                                        Hi,

                                        below link

                                        https://postimg.org/image/iusdou5dz/

                                        where we use
                                        Q_PROPERTY( QBrush brush READ getBrush WRITE setBrush DESIGNABLE true)

                                        property name is brush value we can see solid and in side their is toolbutton,
                                        how it is exposed?.

                                        Thanks,

                                        Pradeep Kumar
                                        Qt,QML Developer

                                        mrjjM 1 Reply Last reply
                                        0
                                        • Pradeep KumarP Pradeep Kumar

                                          Hi,

                                          below link

                                          https://postimg.org/image/iusdou5dz/

                                          where we use
                                          Q_PROPERTY( QBrush brush READ getBrush WRITE setBrush DESIGNABLE true)

                                          property name is brush value we can see solid and in side their is toolbutton,
                                          how it is exposed?.

                                          Thanks,

                                          mrjjM Offline
                                          mrjjM Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on last edited by
                                          #21

                                          @Pradeep-Kumar
                                          Hi, that is not part of the QBrush. That is
                                          part of the editor. Some sort of color picker.

                                          The documentation for the Editor should clearly state the requirements of
                                          making an add-in and allow properties to be edited.

                                          Since this is NOT Creator, we cannot know how to do it but siemens will :)

                                          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