Regarding the exposing of the properties using Q_Property



  • Hi,

    Q_PROPERTY macro is used to expose properties, can we expose the objects as member

    Ex: Q_PROPERTY(QLineEdit lineEdit,READ getLineEdit WRITE setLineEdit,NOTIFY emitValue or DESIGNABLE true)

    in func setLineEdit()
    {
    add the values from lineedit to the label // Ex: do the user implementation here.
    }

    QLineEdit getLineEdit ()
    {
    return lineEdit; //
    }

    Not only QLineEdit, other Objects which are widgtes Ex: QComboBox,QSpinBox,QDoubleSpinBox,QProgressBar. etc.......

    Can u guys clarify and provide the guidance,

    Thanks,


  • Qt Champions 2016

    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.



  • Hi,

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

    Will be needfull.

    Thanks,



  • 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,...


  • Qt Champions 2016

    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.



  • 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,


  • Qt Champions 2016

    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.



  • 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,



  • 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,


  • Qt Champions 2016

    @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.



  • 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,


  • Qt Champions 2016

    @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.



  • 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,


  • Qt Champions 2016

    @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.



  • @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,


  • Qt Champions 2016

    @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.



  • 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,



  • 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,


  • Qt Champions 2016

    @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. ?



  • 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,


  • Qt Champions 2016

    @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 :)



  • i was going through another link

    https://doc.qt.io/archives/qq/qq18-propertybrowser.html

    in
    Extending the Framework section , they have property name and value, with spinbox , combobox, toolbutton.

    Can the user manually create and expose using Q_PROPERTY or any other way?.

    I want toolbutton and combobox in value column of property editor , how can it be acheived?.

    Thanks,


  • Qt Champions 2016

    @Pradeep-Kumar
    Hi
    Yes those samples are example of writing a property editor for us use in own program.
    Just like Creator has its own.

    But this is for Qt. Are you not talking about
    integrating inside another program from siemens ( some editor)?
    Not your own own code / program ?

    • Can the user manually create and expose using Q_PROPERTY or any other way?.
      Where do you mean ? Expose from where ?
      In Qt and Creator, this is exported via DLLS/Plugins so user can make a custom plugin for Creator.

    Where are you trying to export something? and to what?



  • k let me make understand .

    i want to add toolbutton and combobox visual elements from Qt code to WinnCC OA property editor.
    When i add as ewo to WinCC OA, i want the property value to show toolbutton and combobox. so the user can select the items in combobox and click to show dialog on toolbutton.

    Thanks,


  • Qt Champions 2016

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

    WinnCC OA property editor.

    Yes so you must use WinnCC OA documentation to do so.

    How can WinnCC OA property editor even see you object ?

    Did you made a plugin for it ?

    Qt cannot do this for you. Its WinnCC OA that must , if its even possible.



  • Hi,

    Posted the same query in WinCC OA forum

    the below is the link

    https://portal.etm.at/index.php?option=com_kunena&Itemid=75&func=view&catid=16&id=4804#4819

    They said its automatically done by Gedi.
    and going through the documentation, and how to provide the properties as string , QVariant so the gedi understands?.

    Thanks,


  • Qt Champions 2016

    @Pradeep-Kumar
    Ok so no QStringList for us.
    Then yes, seems it just need to be normal Qt properties ( with Q_PROPERTY)
    and Gedi ( what ever that is) should just do it.



  • k thats what i am figuring what datatypr should i use to make Gedi understand , so i will get toolbutton and combobox.

    Thanks,


  • Qt Champions 2016

    @Pradeep-Kumar
    Well the dude says it takes QColor, QPen, QBrush, QFont, QPoint
    so I would just try and see what you get :)



  • Thats what i m figuring but the thing is i require the root of how it has be done.

    Thanks,


  • Qt Champions 2016

    @Pradeep-Kumar

    • i require the root of how it has be done.

    in Qt or Gedi related ?



  • Hi,

    from Qt perspective , and how gedi will come to know to provide toolbutton.

    Thanks,


  • Qt Champions 2016

    @Pradeep-Kumar

    Well just define properties and make sure you have Q_OBJECT macro in the class.
    Then Qt part should be fine.

    For Gedi, you should ask other forum. It's not possible to know what is required for Gedi to load
    your code. With Creator it's a plugin (DLL) but i have no idea what Gedi is or how to make it load
    any Qt code and in what form that code should be.

    So the most important info is still msising

    What does Gedi support / wants / have ?



  • Hi,

    @mrjj

    using the datatypes bool i am able to get combobox in extended properties.

    And using QBrush,QColor i am getting toolbutton,

    Q_PROPERTY(QBrush brush READ getBrush WRITE setBrush DESIGNABLE true)
    
    void BaseWidget::setBrush(QBrush brush)
    {
       //    m_brush = brush;
    
       m_widget = new QWidget;
       m_widget->setWindowTitle("toolbutton");
       m_widget->show();
    }
    
    QBrush BaseWidget::getBrush()
    {
       return m_brush;
    }
    

    on click of toolbutton, we need the widget which we created , but the default widget is poping up, how can it be avoided?.

    Thanks,


  • Qt Champions 2016

    Hi
    -click of toolbutton, we need the widget which we created , but the default widget is poping up, how can it be avoided?

    I have no idea what you mean :)

    Can you please show code for

    • the widget which we created
      ( what widget ?)

    and the code click of toolbutton
    and then what default widget is. ?

    if you mean that , inside Gedi, the editor there - shows a default something and not Class X, you have created
    then please tell more what you do. Else it might be better to ask Gedi forum.



  • Hi,

    When we click on tollbutton,

    https://i.imgsafe.org/739c70e6f0.png

    setter function is called then, the below widget is poping up

    https://i.imgsafe.org/73a0892228.png

    , after click on ok in the above widget , the widget which we created is poping up.

    https://i.imgsafe.org/73a49cabfd.png

    This widget we created.

    My question was when we click on tollbutton in extended properties , cant we have 3 image widget to get poped up?.

    Q_PROPERTY(QBrush brush READ getBrush WRITE setBrush DESIGNABLE true)
    
    void BaseWidget::setBrush(QBrush brush)
    {
       //    m_brush = brush;
    
       m_widget = new QWidget;
       m_widget->setWindowTitle("toolbutton");
       m_widget->show();
    }
    
    QBrush BaseWidget::getBrush()
    {
       return m_brush;
    }
    

    Thanks,


  • Qt Champions 2016

    @Pradeep-Kumar
    Sorry, i don't know that. It is not a Qt thing so whatever that "extended properties"
    really is, I guess its the one who controls what shall be opened.
    So i guess it sees the Brush and then the Brush Dialog comes.
    So unless you can register a Type and a Window for that type, i guess you
    cannot.

    Maybe there is some sort of Custom Type that allows custom windows.



  • can u explain how to register the type for WinCC OA?.

    Thanks,


  • Qt Champions 2016

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

    can u explain how to register the type for WinCC OA?.

    He can't, and neither can I. You should really ask that question - about substituting the dialog window with your own one - on the Gedi forums, as it entirely depends on the application. If the application doesn't have that feature, you won't be able to do it.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.