Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
Some future release
-
None
Description
This issue provides a concept for a QTuple implementation based on a QVariantList and latest Qt (6.7.2 as of issue creation; very likely works with anything newer).
It references (partly old) issues #QTBUG-21147, #QTBUG-22441 and #QTBUG-3283
The concept makes a QList/QVector immutable (at least to higher level implementations such as QML, JS and Python)
A use case I see for immutable tuples is in some serialization context where we sometimes want to make sure a data structure cannot be (easily) mutated by some (bad) JS code (even QWidget code may profit from this).
Attached is a minimal implementation plus an example using it with QDataStream to visualize the use case:
qtuple-reference-project.tar.gz
The implementation is pretty feature complete (please see comments in qtuple.h).
However (like always) some things are missing to make it a reality:
- Documentation and tests
take resources; only makes sense when the concept is accepted in the first place
- QML/JS/PySide6 do not not understand QTuple directly of course; Hard to say how much effort this would be (needs planning)
- QVariantList::toTuple() would be a nice addition; it is optional
Additional notes and restrictions:
- By design there is no (at least easy) way to convert a QTuple back into a QVariantList. I don't think this would make much sense, because data is "owned" by underlying C++ objects. If data needs to be mutable it is more efficient to use a QVariantList/QList<T> instead.
- I will not go beyond QVariantList, because this doesn't hold much value (prove me wrong!
)
I would be happy about some feedback!