Optimalisation Qt QML
-
Hi,
I exchange data between Qt and QML byQ_PROPERTY.
Please someone tell me how can I optimize exchange bool data? I am currently doing the following:Qt:
Q_PROPERTY(bool rs0State READ rs0State WRITE setRs0State NOTIFY rs0StateChanged) Q_PROPERTY(bool rs1State READ rs1State WRITE setRs1State NOTIFY rs1StateChanged) Q_PROPERTY(bool rs2State READ rs2State WRITE setRs2State NOTIFY rs2StateChanged) Q_PROPERTY(bool rs3State READ rs3State WRITE setRs3State NOTIFY rs3StateChanged)QML:
active: if (systemController.rs0State === true) return true else return falseThe QBitArray doesnt't work in QML,
-
And it is possible send
Structdata to QML byQ_PROPERTY?@Damian7546 https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#sequence-type-to-javascript-array
you can use vector<bool>, QList<bool>, qvector<bool>
remember QML works with Java Script. C++ code can not be added to qml simply. -
Hi,
I exchange data between Qt and QML byQ_PROPERTY.
Please someone tell me how can I optimize exchange bool data? I am currently doing the following:Qt:
Q_PROPERTY(bool rs0State READ rs0State WRITE setRs0State NOTIFY rs0StateChanged) Q_PROPERTY(bool rs1State READ rs1State WRITE setRs1State NOTIFY rs1StateChanged) Q_PROPERTY(bool rs2State READ rs2State WRITE setRs2State NOTIFY rs2StateChanged) Q_PROPERTY(bool rs3State READ rs3State WRITE setRs3State NOTIFY rs3StateChanged)QML:
active: if (systemController.rs0State === true) return true else return falseThe QBitArray doesnt't work in QML,
@Damian7546 said in Optimalisation Qt QML:
QML:
active: if (systemController.rs0State === true) return true else return falseThis part is an overkill. Do this instead:
active: systemController.rs0State -
Apart from @sierdzio suggestion what is the other optimization are you looking for ?
Can add more details to your question. -
@sierdzio thanks for suggestion .
@dheerendra
I would like to instead four Q_PROPERTY use only one. I tried withQBitArraybut it not possible refer to an item array from QML. -
Then perhaps you can try with an enum set up to be a Q_FLAG.
Getting it to work on QML side will be a bit tricky but should be possible. -
And it is possible send
Structdata to QML byQ_PROPERTY? -
And it is possible send
Structdata to QML byQ_PROPERTY?@Damian7546 said in Optimalisation Qt QML:
And it is possible send
Structdata to QML byQ_PROPERTY?Yes, look into Q_GADGET.
But if you do that, you will most likely end up using more memory than 4 * bool (so 4 * int).
-
And it is possible send
Structdata to QML byQ_PROPERTY?@Damian7546 https://doc.qt.io/qt-5/qtqml-cppintegration-data.html#sequence-type-to-javascript-array
you can use vector<bool>, QList<bool>, qvector<bool>
remember QML works with Java Script. C++ code can not be added to qml simply.