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
2
votes
2 answers

How are signals emitted through Q_PROPERTY caught?

http://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html class Message : public QObject { Q_OBJECT Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged) public: void setAuthor(const QString &a) { …
Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411
2
votes
1 answer

How to expose a pointer to a Q_GADGET to QML through a Q_PROPERTY

I have a Q_GADGET MyGadget defined in a file mygadget.h #include class MyGadget { Q_GADGET Q_PROPERTY(int value READ value CONSTANT) public: MyGadget() = default; MyGadget(int i) : _value{i} { } int…
Corristo
  • 4,911
  • 1
  • 20
  • 36
2
votes
1 answer

For a NOTIFY signal on a property, what difference does it make if I give it a parameter?

Suppose I have a class that looks like this: class Something : QObject { Q_PROPERTY(int something READ getSomething NOTIFY somethingChanged) // ... signals: void somethingChanged(); } According to the documentation, declaring…
JesseTG
  • 2,025
  • 1
  • 24
  • 48
2
votes
0 answers

Creating a QML type whose properties are read-only except for initialization?

I want to implement a QML type in C++. Said QML type is supposed to be loaded from a Component or similar, like so: Component { id: jesseMaker JesseType { id: doge something: "wow" oops: 67 yes: "hurray" } } Notice how…
JesseTG
  • 2,025
  • 1
  • 24
  • 48
2
votes
2 answers

How to override a Q_Property?

Consider these classes: Class A : public QObject { ... Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged) virtual int value() { return m_value; } void setValue(int v) { m_value = v; Q_EMIT valueChanged();} …
Silgaer22
  • 77
  • 3
  • 7
1
vote
1 answer

Why doesn't this add the QObject* in QVector

I've two ViewModels, MainVM and AddVM. In main.cpp, MainVM is declared this way: MainVM *mvm; int main(int argc, char *argv[]) { ... mvm = new MainVM(); ... engine.rootContext()->setContextProperty("mainContext", mvm); …
user6283344
1
vote
1 answer

Q_PROPERTY with private setter

I have an QObject with properties accessible from QML. Something like: Class C : public QObject { Q_OBJECT public: explicit C(QObject * parent = nullptr); Q_PROPERTY(QString ro_text READ ro_text WRITE setRo_text NOTIFY ro_textChanged) }; Is it…
Martin
  • 333
  • 1
  • 8
1
vote
1 answer

How to get Q_PROPERTYs to show in Design Viiew

I have a class derived from QPushButton with Q_PROPERTYs but they do not appear in the Property Editor of Design Mode. There is a QPushButton promoted to my custom class in the design view and I would expect the properties to automatically display…
user4913118
  • 105
  • 1
  • 8
1
vote
1 answer

How to use QPROPERTY in QPalette?

I'm trying to use a Q_PROPERTY set in my stylesheet to change the value in QPalette, is this possible? For example, if I set QStyle to Fusion in my MainWindow widget, is it possible to change Qt::Window, etc using this method? Everything compiles…
RyuMake
  • 25
  • 3
1
vote
2 answers

Qt Qml connect to a signal of a QObject property of a Context Property

So this may seem like a strange setup. I have a C++ object that inherits from QObject called "MasterGuiLogic" for simplicity. It is created with a pointer to another object called "MainEventBroker" which as you might guess handles all of my…
Dalen Catt
  • 111
  • 1
  • 9
1
vote
1 answer

Use Q_PROPERTY's from a costum class in QML

I'm stuck with a "design/implemantation" problem in Qt. At the moment I'm not even sure if thats a smart design... That's my first post here and I don't really know where to start... So I'll try is this way... At the moment I have something like…
mBucks
  • 15
  • 5
1
vote
0 answers

Can QObjects have more than one static property of the same name?

Can a user-made subclass of Parent of QObject have multiple Q_PROPERTYs of the same name (possibly with different types)? What if I subclass Parent to Child, and give that a similarly-named Q_PROPERTY? Like so: #include class Parent :…
JesseTG
  • 2,025
  • 1
  • 24
  • 48
1
vote
1 answer

User type in Q_PROPERTY error 'staticMetaObject' is not a member of 'blah'

I have some data types defined as enum in a namespace. I wanted to use Q_PROPERTY, that would return the data types... But I get error: 'staticMetaObject' is not a member of 'blah' So it seems, if I want to create my own types, and use them in…
Thalia
  • 13,637
  • 22
  • 96
  • 190
1
vote
1 answer

How to build a generic method to connect the notifySignal of different Q_PROPERTY types to a void slot(QVariant) from the property char * name?

I'm trying to write a method, with two parameters : the Q_PROPERTY name (char *) and the QObject * associated with, that permit to connect the notifySignal (if exists) of the Q_PROPERTY, to a void slot(QVariant), or to a slot dynamically builded…
1
vote
1 answer

using Q_PROPERTY with a NOTIFY item for a QString

I have a widget-based class. It has two private QString members. I would like to be able to use signals to notify when the values are changed. So for both variables I have a setter and a getter. I also have a signal. Question: Can they both use…
murison
  • 3,640
  • 2
  • 23
  • 36