Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75480

QML/C++ Conversions: Support more Lists, Maps and Hashes without QVariant

    XMLWordPrintable

Details

    • All

    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

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              scorp1us Jason Hihn
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes