Unsolved Qt\QML Q_PROPERTY() REQUIRED syntax issue
-
Hi all,
From here:
https://doc.qt.io/qt-5/properties.htmlI see that is possible to define the REQUIRED flag for each qproperty that needs to be declared by the user.
Unfortunately I can find any example (not event in Qt source code) where a Q_PROPERTY is defined with REQUIRED flag.
Declaring this outside brackets as specified by documentation gives me compilation errors:
Q_PROPERTY(QString test READ getTest WRITE setTest NOTIFY testChanged) REQUIREDDo you have any advice?
Regards.
-
Q_PROPERTY(QString test READ getTest WRITE setTest NOTIFY testChanged REQUIRED)
-
this gives me error at compilation time:
Parse error at "REQUIRED"
-
@simone-malvezzi said in Qt\QML Q_PROPERTY() REQUIRED syntax issue:
Q_PROPERTY(QString test READ getTest WRITE setTest NOTIFY testChanged) REQUIRED
Beware, I have never used QML!
I do not see your syntax complies with the specification. If, say,
NOTIFY
is inside theQ_PROPERTY()
parentheses, why is yourREQUIRED
outside those parentheses? Why not:Q_PROPERTY(QString test READ getTest WRITE setTest NOTIFY testChanged REQUIRED)
EDIT Oh, I see, your outside way does correspond to the syntax shown, if I look closely!
_PROPERTY(type name (READ getFunction [WRITE setFunction] | MEMBER memberName [(READ getFunction | WRITE setFunction)]) ... [FINAL]) [REQUIRED]
-
@simone-malvezzi said in Qt\QML Q_PROPERTY() REQUIRED syntax issue:
this gives me error at compilation time:
Parse error at "REQUIRED"
Are you using Qt 5.15?
-
I see, REQUIRED was added from 5.15, actually I'm using Qt 5.12.7 that's why I can't use this.
-
Yup, exactly, it's a new thing.
-
@simone-malvezzi
Always a good idea to state your Qt version when asking a question like this! :)