Details
-
Suggestion
-
Resolution: Duplicate
-
P2: Important
-
None
-
5.12.3
-
None
Description
Many times I want to return a QList<QPoint> or similar to QML. This should be transparent as the other conversions. The current scenario using QVariant is flexible, but it requires adding additional API functions that are just needed for QML.
example:
QList<QPoint> centers(); // what I want in C++QVariant centersVariant() // what I need to do to interop with QML.
QList<QPoint>{
{0,1}, {2,3} => ["0,1", "2,3"] (and back).
QList<QPointF>{
{0.0,1.0}), {2.0,3.0} => ["0.0,1.0", "2.0,3.0"] (and back).
per https://doc.qt.io/qt-5/qtqml-cppintegration-data.html
- QList<int>
- QList<qreal>
- QList<bool>
- QList<QString> and QStringList
- QVector<QString>
- std::vector<QString>
- QList<QUrl>
- QVector<QUrl>
- std::vector<QUrl>
- QVector<int>
- QVector<qreal>
- QVector<bool>
- std::vector<int>
- std::vector<qreal>
- std::vector<bool>
Are supported.
However the containers don't yet support containing:
- QColor color
- QFont font
- QDateTime date
- QPoint point,
- QPointF point
- QSize, QSizeF size
- QRect, QRectF rect
- QMatrix4x4 matrix4x4
- QQuaternion quaternionQVector2D, QVector3D, QVector4D vector2d, vector3d, vector4d
Which are otherwise convertible. (Bold are ones I am actually using)
Additionally, for QMaps and Hashes, those should also be supported. For example:
{{QMap<QString,QString> {
{"a", 1}, {"b", 2}} => {"a": 1, "b":2} }}
Though there are some issues because some types like QPoint and QRect don't define > for QMap or a key hash for QHash.
Attachments
Issue Links
- duplicates
-
QTBUG-71574 Provide a better way to register sequential and associative types for usage in QML
- Closed