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

Using qRegisterMetaType and Q_PROPERTY with a pointer type causes an error

    XMLWordPrintable

Details

    • 40a6845bcce22aca96e1dee26360bdff3e9520fb (qtdeclarative)

    Description

      When registering a pointer type with qRegisterMetaType<ExampleModel*>, exposing the pointer to qml as context property and trying to use it in

      Q_PROPERTY(ExampleModel *model READ model WRITE setModel NOTIFY modelChanged)

      leads to an error "Unable to assign ExampleModel to ExampleModel*" and the QML is not shown.

      The above scenario works in Qt 5.1.1 (with QtQuick2ApplicationViewer), it doesn't work in Qt 5.3 with QtQuick2ApplicationViewer, and it works in Qt 5.3 with QQmlApplicationEngine, but it still prints the "Unable to assign .." error message. Thus this causes greatest trouble to QtQuick2ApplicationViewer users who try to upgrade to Qt 5.3.

      The attached SupportExamples.tar.gz contains two projects to reproduce the error: one for QtQuick2ApplicationViewer and another for QQmlApplicationEngine.

      There exists a workaround though: using qmlRegisterType<ExampleModel> instead of qRegisterMetaType<ExampleModel*> seems to do the trick.

      Attachments

        1. qtbug39614_assert_stack.txt
          13 kB
          Friedemann Kleint
        2. qtbug39614.zip
          24 kB
          Friedemann Kleint
        3. SupportExamples.tar.gz
          20 kB
          Qt Support
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            ulherman Ulf Hermann
            qtcomsupport Qt Support
            Votes:
            2 Vote for this issue
            Watchers:
            8 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes