Error in QML: Unknown method return type: Organisation::ICar*. Using Q_DECLARE_METATYPE and qmlRegisterType


Error in QML: Unknown method return type: Organisation::ICar*. Using Q_DECLARE_METATYPE and qmlRegisterType



Please go through my code.



My interface:


namespace Organisation
{

class ICar
{
// ---pure virtual functions---
};

}

Q_DECLARE_INTERFACE(Organisation::ICar, "com.organisation.ICar/1.0")



My Derived class:


class Toyota: public QObject, public virtual Organisation::ICar
{
Q_OBJECT
Q_INTERFACES(Organisation::ICar)

// ---All implementations---
}



In the constructor I register the type to QML using


qmlRegisterType<Toyota>("organisation.com.Toyota", 1, 0, "Toyota");



Above one compiles fine, but give error in QML (Unknown method return type error)


qmlRegisterType<Organisation::ICar>("organisation.com.Toyota", 1, 0, "Toyota");
qmlRegisterType<Organisation::ICar>("organisation.com.IToyota", 1, 0, "Toyota"); */



Above two gives



error: C2039: 'staticMetaObject': is not a member of 'Organisation::ICar'



Gets same error if I give


Q_DECLARE_METATYPE(QQmlListProperty<Organisation::ICar>)



or


Q_DECLARE_METATYPE(Organisation::ICar>)



in the header file. It is outside all classes and namespaces



Another class called UsedCars creates objects of Toyota and supplies to other modules as Organisation::ICar pointers.


UsedCars


Toyota


Organisation::ICar



ICar, Toyota, UsedCars, etc. are part of a library named UsedCars.


ICar


Toyota


UsedCars


UsedCars



Another module called Dealership uses the UsedCars library.
Dealership creates cars and stores it as Organisation::ICar pointers.


Dealership


UsedCars


Dealership


Organisation::ICar



These pointers are stored in a QList<Organisation::ICar *>.


QList<Organisation::ICar *>



In the dealership class there is a read function that returns these cars pointers used by Q_PROPERTY defined in the header


Q_PROPERTY


Q_PROPERTY(QQmlListProperty<Organisation::ICar> carList READ carList)



function to return carList:


QQmlListProperty<Organisation::ICar> Dealership::carList()
{
return QQmlListProperty<Organisation::ICar>(this, this->carStockList());
}



carStockList() returns the QList of pointers of type Organisation::ICar*


carStockList()


QList


Organisation::ICar*


QList<Organisation::ICar *> carStockList // list returned by carStockList()



When I use the carList propery in QML and it gives error:


carList



Unknown method return type: Organisation::ICar*



QML is getting the Organisation::ICar pointers but is unknown.
I want to access the data of the Car objects each Organisation::ICar* pointer is pointing to.


Organisation::ICar


Car


Organisation::ICar*



I have given


Q_DECLARE_METATYPE(QQmlListProperty<Organisation::ICar>)



in the dealership class header outside the class.



I think the above statement is needed, otherwise QML does not even get Organisation::ICar* pointer.


Organisation::ICar*



Sorry for the long post. I have been searching for a solution for 2 days, got some suggestions and reached this far.



I feel like there is some issue where with the type registration or the pointer type used with QQmlListProperty.


QQmlListProperty



Any suggestions on what I am doing wrong?





public virutal Organisation::ICar or public virtual Organisation::ICar??
– eyllanesc
Jun 28 at 18:53



public virutal Organisation::ICar


public virtual Organisation::ICar





Sorry typo here only....its virtual in my code. Corrected the question.
– samsix
Jun 28 at 18:59






IIRC there was an issue with types that are in namespaces.
– dtech
Jun 28 at 19:02





If you want help, you will have to try harder, please provide a decent Minimal, Complete, and Verifiable example
– eyllanesc
Jun 28 at 19:02





Considering you are new to QML, I'd suggest you take it easy. You are rushing into a complicated subset of the language, so tread carefully and brace for frustration.
– dtech
Jun 28 at 19:09










By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

api-platform.com Unable to generate an IRI for the item of type

How to set up datasource with Spring for HikariCP?

PHP contact form sending but not receiving emails