-2

I am developing a bb10 app in cascades. Here is the snippet for the header file

//applicationui.hpp
Q_PROPERTY(int metric READ getMetric WRITE setMetric NOTIFY metricChanged)
public:
    int getMetric();
    void setMetric(int newMetric);

signals:
void metricChanged(int);
private:
    int m_metric;


//applicationui.cpp
ApplicationUI::ApplicationUI(bb::cascades::Application *app) :
    QObject(app)
{
    qml->setContextProperty("_app", this);
    // Set created root object as the application scene
    app->setScene(root);

    m_metric = 1;

}

int ApplicationUI::getMetric(){
    return m_metric;
}

void ApplicationUI::setMetric(int newMetric){
m_metric = newMetric;
emit metricChanged(m_metric);
}

In my main.qml I have a RadioGroup whose selectedIndex I would like to set depending on the metric value

RadioGroup {
                id: distanceMetric
                Option { id: option1; text: "Miles"}
                Option { id: option2; text: "Kilometers"}
                onCreationCompleted: {
                    distanceMetric.selectedIndex = _app.metric
                }
 }

But this doesnt seem to be working as expected. Any suggestions would be appreciated. Thanx

neeraj
  • 53
  • 1
  • 5

2 Answers2

1

Does you class inherit QObject (I guess it must as it seems to be a widget)?

Did you include the Q_OBJECT macro?

Maybe the doc could help if none of the above solve your issue? I'm not saying RTFM, just sometimes if you are using the website version of the docs, I find it a bit hard to find things.

Uflex
  • 1,396
  • 1
  • 13
  • 32
1

I suspect your QML scene is being created before you are setting the metric value to 1. Try changing this:

m_metric = 1;

to this:

setMetric(1);

so that the QML binding can be notified of the change.

David
  • 11
  • 1
  • 1