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

QtQuick: Unknown method return type QAbstractItemModel *

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.10.1
    • None
    • Qt 5.10.1, MSVC 2015 32b, Windows 7 SP1.
       

    Description

      I have a QObject-derived class which returns a QAbstractItemModel * from a Q_INVOKABLE function.  When trying to assign the result of this function to a parameter in a QML object, I get:

      Error: Unknown method return type: QAbstractItemModel*

      What really got me was that I didn't have this error for a long time, with all the same C++ code. Then I happened to remove an "import QtQuick.Controls 1.4" from another, seemingly unrelated, component which was also being loaded at the same time (into the same context). Only then did I start getting this error.

      If I change my C++ code to return a QObject* instead of a QAbstractItemModel* then the QML works again, w/out complaining.  But of course I'd rather return the actual type (also for C++ usage, etc).

      The affected code is pretty basic, but I haven't tried isolating a standalone example.

      In C++:

      Q_INVOKABLE QAbstractItemModel * ModuleFactory::widgetsModel(const QByteArray &parentId = QByteArray(), QObject *parent = nullptr);

       

      In QML (ModuleFactory is a singleton):

      import QtQuick 2.10
      Menu {
        ...
        readonly property var dataModel: ModuleFactory.widgetsModel();
      }

      I also tried adding QtQml and QtQml.Models imports, but no difference.  If I add QtQuickControls 1.4 import, it works.

      Please let me know if I can provide more information or if I'm missing something.

      Well a good clue is that the only reference to registering QAbstractItemModel which I could find is in Controls 1... https://code.woboq.org/qt5/qtquickcontrols/src/controls/plugin.cpp.html#178

      So maybe this is by design, but it seems strange.  Obviously I can register the type myself as a workaround, but the class "belongs" to Qt after all.

      Thank you,
      -Max

      Attachments

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

        Activity

          People

            shausman Simon Hausmann
            mpaperno Maxim Paperno
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes