Unsolved 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,
-
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, allQObject
subclasses (likeQLineEdit
) can't be returned by value, but by address (as pointers). Same goes for the properties - you can store onlyQObject *
in the variant, thus your class that derive fromQObject
can only be exposed (in the sense ofQObject::property()
andQObject::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,...
useQ_PROPERTY(QLineEdit* lineEdit,...
-
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,
-
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,
-
@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,
-
@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
andQObject::property
methods by name. There's no other automation put in place for you out of the box (you even need to cast theQVariant
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 codeDesigner Plugin is only for Qt designer?.
Thanks,
-
@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,
-
@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?.as u have also had hands on WinCC OA, can u provide guidance?.
Thanks,
-
@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,