我正在级联开发一个 bb10 应用程序。这是头文件的片段
//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);
}
在我的 main.qml 中,我有一个 RadioGroup,我想根据指标值设置其 selectedIndex
RadioGroup {
id: distanceMetric
Option { id: option1; text: "Miles"}
Option { id: option2; text: "Kilometers"}
onCreationCompleted: {
distanceMetric.selectedIndex = _app.metric
}
}
但这似乎没有按预期工作。任何建议,将不胜感激。谢谢