You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Note: the key for the flags use all capitals like in the Qt version of qproperty
136
137
137
138
> Note: currently the rust name must be in camel case or specified like `#[cxx_name = "my_getter"]` if not
138
139
139
140
It is also possible to use any combination of custom functions or omit them entirely, but if flags are specified, read must be included as all properties need to be able to be read.
140
141
141
-
Using the read flag will cause CXX-Qt to generate a getter function with an automatic name based off the property. e.g. `#[qproperty(i32, num, read)]` will have a getter function generated called get_num in Rust, and getNum in C++.
142
+
Using the read flag will cause CXX-Qt to generate a getter function with an automatic name based off the property. e.g. `#[qproperty(i32, num, READ)]` will have a getter function generated called get_num in Rust, and getNum in C++.
142
143
143
144
If a custom function is specified, an implementation both in qobject::MyObject and and export in the bridge is expected.
144
145
145
146
### Examples
146
147
147
-
-`#[qproperty(TYPE, NAME, read)]` A read only prop
148
-
-`#[qproperty(TYPE, NAME, read = myGetter, write, notify)]` custom getter provided but will generate setter and on-changed
149
-
-`#[qproperty(TYPE, NAME)]` is syntactic sugar for `#[qproperty(TYPE, NAME, read, write, notify)]`
150
-
-`#[qproperty(TYPE, NAME, write)]` is an error as read was not explicitly passed
148
+
-`#[qproperty(TYPE, NAME, READ)]` A read only property
149
+
-`#[qproperty(TYPE, NAME, READ = myGetter, WRITE, NOTIFY)]` custom getter provided, but will generate setter and on-changed
150
+
-`#[qproperty(TYPE, NAME)]` is shorthand for `#[qproperty(TYPE, NAME, READ, WRITE, NOTIFY)]`
151
+
-`#[qproperty(TYPE, NAME, WRITE)]` is an error as read was not explicitly passed
152
+
153
+
### Available Flags
154
+
155
+
-`READ` or `READ = my_getter`
156
+
- Specifies that the property should be readable (*always required if flags are passed*), with optional user defined getter
157
+
-`WRITE` or `WRITE = my_setter`
158
+
- Specifies that the property should be writeable, with optional user defined setter
159
+
-`NOTIFY` or `NOTIFY = my_on_changed`
160
+
- Specifies that the property should emit a notify signal on change, with optional user defined signal name
161
+
-`CONSTANT`
162
+
- Specifies that the property should be constant (implication is that the getter returns the same value every time for that particular instance)
163
+
-__`CONSTANT` is not available for properties which use `WRITE` or `NOTIFY` and will not compile__
164
+
-`REQUIRED`
165
+
- Specifies that the property must be set by a user of the class, useful in QML as the class cannot be instantiated unless the property has been set
166
+
-`FINAL`
167
+
- Specifies that the property will not be overriden by a derived class
168
+
-`RESET = my_reset`
169
+
- Specifies a function to reset the property to a default value, user function __must__ be provided or it will not compile
Copy file name to clipboardExpand all lines: book/src/getting-started/2-our-first-cxx-qt-module.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -176,6 +176,8 @@ Also, we can't move the `QObject`, which is why it is behind a Rust [`Pin`](http
176
176
177
177
CXX-Qt will generate getters and setters for all properties of our `struct`.
178
178
That's where the `number()` and `set_number()` functions used by `increment_number()` come from.
179
+
See the [`QProperty` section](../bridge/extern_rustqt.md#properties) for details on user defined properties.
180
+
179
181
For more details on what you can do with the `QObject` from Rust and what functions CXX-Qt will generate for you, take a look at the [`QObject` page](../concepts/generated_qobject.md).
180
182
181
183
And that's it. We've defined our first `QObject` subclass in Rust. That wasn't so hard, was it?
0 commit comments