I have this code.
class Pet
{
public:
Pet(const QString& nm)
: name(nm)
{}
const QString& name() const { return nm; }
private:
QString nm;
}
class Dog : public QObject, public Pet
{
Q_OBJECT
public:
Dog(QObject* prnt)
: QBject(prnt),
Pet("Tommy")
{}
}
Exposing this to QML
QQmlApplicationEngine engine;
engine.rootContext()->setProperty("petDog", new Dog(&engine));
// QML Item
console.log(petDog.name()) // TypeError: Property 'name' of object Dog(0x0XXXXX) is not a function
What is the solution to expose all the methods of a C++ class to QML? Thanks