Qml Interface Property
-
wrote on 31 Oct 2013, 19:37 last edited by
There seems to be a current limitation of not being able to define an interface property in Qml, like you can in C++. Is this a bug, or by design?
With the below Qml code, you will get an error of "MyInterface is not a type" when trying to declare a property that is an interface.
In C++
@
class MyInterface
{
// Class definition
}class MyObject: public QObject
{
Q_OBJECT
Q_PROPERTY( MyInterface* interface READ getInstance() WRITE setInterface() )
}// In main, register interface
qmlRegisterInterface<MyInterface>( "MyInterface" );
@In Qml
@
// This is valid
MyObject {
interface: SomeInterfaceInstance {}
}// This isn't valid
Item {
property MyInterface: SomeInterfaceInstance {}
}
@ -
wrote on 13 Aug 2024, 16:39 last edited by
2024year... problem is still the same
-
You have to use the
Q_DECLARE_INTERFACE
andQ_INTERFACES
macros