Reputation: 2443
Consider:
class Utility : public QObject
{
Q_OBJECT
public:
explicit Utility(QObject* parent = nullptr) : QObject(parent) {}
Q_INVOKABLE void test(const QAbstractItemModel* model)
{
}
};
Set up in main
via qmlRegisterSingletonInstance("pgqt34", 1, 0, "Utility", &utility);
and QML is:
import QtQuick 2.15
import QtQuick.Window 2.15
import pgqt34 1.0
Window {
width: 640
height: 480
visible: true
title: qsTr("Hello World")
ListModel {
id: listModel
}
onActiveChanged: {
Utility.test(listModel);
}
}
I consistently get Error: Unknown method parameter type: const QAbstractItemModel*
for Qt 5.15.2 compilations, but Qt 6.x+ works OK. What is wrong here?
Upvotes: 0
Views: 101
Reputation: 1425
Straight way:
Q_INVOKABLE void test(const QObject* obj) { auto model = qobject_cast(obj); }
Declare QAbstractItemModel*
as a metatype. But, I'm not sure if it's a working solution.
Upvotes: 1