Details
-
Suggestion
-
Resolution: Done
-
P2: Important
-
None
-
None
-
8e904d9c8b36af4310070aa68ddb04cf33520b52 (qt/qtdeclarative/dev)
Description
I have an invokable function in C++ that should be const with const parameters:
Q_INVOKABLE QPoint findClosestAvailableTilePos(const QPoint &tilePos, const SceneItemComponent *sceneItemComponent = nullptr) const;
I register it with QML like this:
qmlRegisterUncreatableType<SceneItemComponent>("Isle", 1, 0, "SceneItemComponent", "SceneItemComponent should not be created in QML");
If I try to call this with a SceneItemComponent object in JavaScript, the parameter simply becomes null in C++. Changing the parameter to a non-const SceneItemComponent* is a workaround, but not that nice, because it means that everywhere I use this function in C++ has to be adapted (and sometimes const_casted).
It would be better if it were possible to use the const type in QML and just get an error if any non-const operations (getters, setters, invokables) were performed on it, if that's even possible. I don't know if e.g. moc even stores constness of functions, or whether such a change to the QML engine would affect performance adversely... but it would be nice to have.
Attachments
Issue Links
- relates to
-
QTBUG-47631 Cannot register both const and non-const versions of a type with QML
- Open
-
QTBUG-70037 QML metatype: A* is not "compatible" with const A*
- Open
- resulted in
-
QTBUG-91350 [REG 5.15->6.0] TapHandler.onTapped: device and button are no longer available
- Closed