Details
Description
Consider the following C++ class:
class TestThing : public QObject { Q_OBJECT QML_ELEMENT QML_SINGLETON public: explicit TestThing(QObject *parent = nullptr); Q_INVOKABLE void foo(const QString &bla); Q_INVOKABLE void foo(TestThing *a); };
And the QML code
Item { property QtObject obj: TestThing; Component.onCompleted: TestThing.foo(obj) }
Full code at https://invent.kde.org/nicolasfella/qmloverload
The QML code will call the QString overload instead of the TestThing * overload, which I find rather unexpected.
Changing the type of the obj property from QtObject to TestThing makes it choose the TestThing overload (as I expect).
What's even more confusing is that when I remove the declarative type registration macros and rely on runtime registration then the behavior changes and the TestThing overload is chosen.
I found this behavior in KDE Plasma after porting to declarative type registration cause a regression.
Qt 6.6
qtbase f4b91d595ce0ec69b01848bfe68d468c63d20d5a
qtdeclarative e1fbca3d7338c63672af7224e6b70ad11aea9332