hei guys ...我在bb10上创建下拉菜单时遇到问题.. 假设我有下拉A和下拉B ..选项 下拉列表A上的onSelectedIndexChange操作将改变下拉列表B的选项.. 这是代码:
RegisterPhone.cpp:
void RegisterPhone::initData(){
JsonDataAccess jda;
QVariantList country = jda.load("app/native/assets/countries.json").toList();
QVariant var;
foreach(var, country){
QVariantMap a = var.toMap();
countries.append(a);
if(a.value("cca3").toString()=="IDN"){
dropDownCountry->add(Option::create().text(a.value("name").toString()).selected(TRUE));
QVariantList b = a.value("callingCode").toList();
codeLabel->setText("+" + b.at(0).toString());
}else{
dropDownCountry->add(Option::create().text(a.value("name").toString()));
}
}
}
void RegisterPhone::initControl() {
connect(buttonReg, SIGNAL(clicked()), this, SLOT(doRegister()));
connect(dropDownCountry, SIGNAL(selectedIndexChanged(int)), this,
SLOT(onSelectedIndex(int)));
connect(codeDropDown, SIGNAL(selectedOptionChanged(bb::cascades::Option*)), this,
SLOT(onSelectedValue(bb::cascades::Option*)));
}
void RegisterPhone::onSelectedIndex(int i){
qDebug() << countries.at(i).toMap();
QVariantMap country = countries.at(i).toMap();
QVariantList codes = country.value("callingCode").toList();
int count = codes.count();
qDebug() << codeDropDown;
if(count>1){
codeDropDown->removeAll();
isDropDown = true;
qDebug() << "count lebih dari 1";
codeLabel->setVisible(false);
codeDropDown->setVisible(true);
foreach(QVariant var, codes){
codeDropDown->add(Option::create().text("+" + var.toString()));
}
codeDropDown->setSelectedIndex(0);
}
else{
isDropDown = false;
qDebug() << "count == 1";
codeLabel->setVisible(true);
codeDropDown->setVisible(false);
if(codes.at(0).toString()==""){
codeLabel->setText("");
}
else{
codeLabel->setText("+" + codes.at(0).toString());
}
}
}
void RegisterPhone::onSelectedValue(bb::cascades::Option* value){
stringCode = value->text();
}
我创建UI没有问题..在构建和运行时工作正常。但是当我选择多次时,它将停止工作.. 我发现问题出在我什么时候
codeDropDown->removeAll()
当我调试时,它也停在这里
void RegisterPhone::onSelectedValue(bb::cascades::Option* value){
stringCode = value->text();
}
我需要此函数来检索callingCode的值
我不知道如何修理它。可以请有人帮助我吗?
请原谅英语不好...... 感谢