Questions tagged [qproperty]

This macro is used for declaring properties in classes that inherit QObject. Properties behave like class data members, but they have additional features accessible through the Meta-Object System.

Q_PROPERTY(type name
       (READ getFunction [WRITE setFunction] |
        MEMBER memberName [(READ getFunction | WRITE setFunction)])
       [RESET resetFunction]
       [NOTIFY notifySignal]
       [REVISION int]
       [DESIGNABLE bool]
       [SCRIPTABLE bool]
       [STORED bool]
       [USER bool]
       [CONSTANT]
       [FINAL])

The property name and type and the READ function are required. The type can be any type supported by QVariant, or it can be a user-defined type. The other items are optional, but a WRITE function is common. The attributes default to true except USER, which defaults to false.

62 questions
25
votes
1 answer

What is the significance of Q_PROPERTY in Qt?

I am not able to understand the usage of Q_PROPERTY. How th Q_PROPERTY helps in making a program defensive? What is it used for? I have seen the forum, but really not able to make its applicaton. I have understood the example, but not it's…
dexterous
  • 6,422
  • 12
  • 51
  • 99
7
votes
1 answer

Dump all properties of a QObject derived object

How to dump all properties of a Qt object? For debugging purpose, e.g. when analyzing objects returned by a factory.
maxschlepzig
  • 35,645
  • 14
  • 145
  • 182
6
votes
2 answers

QList> passed into QML

I'm trying to pass a 2d QList as a Q_PROPERTY into QML, however, inside QML and i am unable to actually access any of the information. some code: c++: the q_property get populated by a q_invokable function in the constructor: void…
Leshii
  • 71
  • 1
  • 5
5
votes
1 answer

Qt - Q_PROPERTY's NOTIFY signal not emited about MEMBER change

I have a private class member variable status and i want to emit a signal with its value everytime it changes. Therefore I use Q_PROPERTY and specify a signal with NOTIFY: #ifndef CAMERACONTROL_H #define CAMERACONTROL_H #include #include…
goulashsoup
  • 2,639
  • 2
  • 34
  • 60
5
votes
2 answers

How to expose property of QObject pointer to QML

I am giving very brief (and partial) description of my class to show my problem. Basically I have setup two properties. class Fruit : public QObject { Q_OBJECT .... public: Q_PROPERTY( int price READ getPrice NOTIFY priceChanged) …
zar
  • 11,361
  • 14
  • 96
  • 178
4
votes
1 answer

How to correctly notify in QQmlListProperty properties?

Whenever I was creating a Q_PROPERTY for later use in Qml I always created a notify signal to tell qml that data changed and needs to be reevaluated. Now having a Q_PROPERTY of the type QQmlListProperty how can I signalize that an item has been…
feedc0de
  • 3,646
  • 8
  • 30
  • 55
4
votes
2 answers

Exposing Q_PROPERTY from private member

In the code I'm working on I need to expose Q_PROPERTY from private member(s) through one integrating QWidget. Something like this would be nice: class MyWidget: public QWidget{ Q_OBJECT Q_PROPERTY(QString headerText MEMBER myLabel.text NOTIFY…
Libor Tomsik
  • 668
  • 7
  • 24
4
votes
1 answer

QSS properties for custom widget: How to implement hover and pressed states

I found this example on the web on how to implement custom properties accessible from QSS for custom QWidgets: https://wiki.qt.io/Qt_Style_Sheets_and_Custom_Painting_Example Does anyone know how can I implement the widget so that I can have…
Jacob Krieg
  • 2,834
  • 15
  • 68
  • 140
3
votes
2 answers

How to animate color of QBrush

I want to animate Color of QBrush. For more details see code below That's my .h file class Cell : public QObject, public QGraphicsRectItem { Q_OBJECT Q_PROPERTY(QBrush brush READ brush WRITE set_Brush) public: QBrush _brush() const; …
OneOne
  • 131
  • 9
3
votes
1 answer

How does Q_PROPERTY() RESET clause work?

When using the Q_PROPERTY macro to define a property to Qt's property system, one of the available clauses is RESET. I know what the reset function is for, and how to create one, but I can't figure out when it would be triggered from QML. I notice…
2
votes
1 answer

Create a Q_PROPERTY to a QObject which has it's own Q_PROPERTY's

I have an QInnerItem with two Q_PROPERTIES class QInnerItem : public QObject { Q_OBJECT Q_PROPERTY(int bar1 READ bar1 WRITE setBar1 NOTIFY bar1Changed) Q_PROPERTY(int bar2 READ bar2 WRITE setBar2 NOTIFY bar2Changed) public: …
Blue7
  • 1,750
  • 4
  • 31
  • 55
2
votes
2 answers

Read C++ QVector of structs in QML

In my C++ class I have struct trackPoint { QString lat; QString lon; QString elevation; }; QVector trackPoints; In QML I want to access this as a multi-dimensional array of lon,lat pairs [[0,1],[1,1],[2,1]] Is this possible…
CitizenFish
  • 312
  • 2
  • 13
2
votes
1 answer

How to remove QML binding on property from C++?

With QML a property value can be based on another object property's value, it is called binding and it will update your value everytime the property you depend on is updated. Like in this example, the implicitWidth of CppItem is half of the parent's…
ymoreau
  • 3,402
  • 1
  • 22
  • 60
2
votes
2 answers

Can I access a QPROPERTY declared as MEMBER in C++?

I have a QQuickItem class with some members used in QML, so they are declared like this : Q_PROPERTY (bool myBool MEMBER _myBool NOTIFY myBoolChanged) If I want to access to this member in C++ code (from another class), do I have a free…
ymoreau
  • 3,402
  • 1
  • 22
  • 60
2
votes
1 answer

Qt: ERROR in Exposing C++ Class to QML

I keep getting the same error when I run the application: qrc:/main.qml:13: ReferenceError: _myClass is not defined Where is the bug? Furthermore, if I want to connect signal myIntChanged to a slot, where should I place my connect? In main.cpp or…
Ale
  • 285
  • 2
  • 7
  • 18
1
2 3 4 5