I basically just want to use multiple derived classes to change a member variable of a base class and to forward that value to qml using qproperty, but for some reason it's not working
car.h
#include <QObject>
class Car : public QObject{
Q_OBJECT
Q_PROPERTY(int seats MEMBER m_seats NOTIFY updateSeats)
public:
explicit Car(QObject *parent = 0);
~Car();
int m_seats;
Q_INVOKABLE void test();
signals:
void updateSeats();
};
car.cpp
#include "car.h"
Car::Car(QObject *parent) :
QObject(parent),
m_seats(0)
{
}
Car::test(){
m_seats = 5;
emit updateSeats();
}
Car::~Car(){}
toyota.h
#include "car.h"
class Toyota : public Car{
Q_OBJECT
public:
explicit Toyota(QObject *parent = 0);
~Toyota();
void foundCar();
};
toyota.cpp
#include "toyota.h"
Toyota::Toyota(QObject *parent)
{
}
Toyota::foundCar(){
m_seats = 4;
emit updateSeats();
}
Toyota::~Toyota(){}
Now, after invoking the foundCar function in class Toyota, if I do console.log(car.seats) in qml I get 0, but I expect it to be 4 because I am modifying it in the derived class. However if I call car.test() from qml and then I print car.seats, the value is 5. I am confused why this is the case. In qml I want car.seats to be 4. What am I missing?
QmlEngine
's by having thisstartGui
function? Can you also show the main function? – Amfasismain()
in your code ? – Mohammad Kanan