خرید بک لینک

Vote count: 0

I have two C++ classes (TrafficLight and Light). Light is a child of TrafficLight. QML can see everything from TrafficLight and nothing from Light, for example...I get the following error when I try to access a method from Light like TrafficLight.get_light(0).get_color()

TypeError: Caot call method 'get_color' of undefined

I exposed my parent class (TrafficLight) to qml (see main below). I assumed it would expose the subclass inside it, as well...but apparently not.

#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include "traffic_light.h"

int main(int argc, char *argv[])
{
    QGuiApplication app(argc, argv);

    QQmlApplicationEngine engine;

    Traffic_Light traffic_light;

    engine.rootContext()->setContextProperty("TrafficLight", &traffic_light);

    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));

    retu app.exec();
}

My question is how would I expose the subclass? I can't just create an instance of Light and expose it the same way I did TrafficLight. Reason being is it won't be the same Light that's inside the TrafficLight. :(

asked 33 secs ago

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 29 فروردين 1395 ساعت: 9:58

صفحه بندی