添加元素以下拉bb 10级联

时间:2013-08-28 09:48:58

标签: blackberry-10

我在Qml文件中有一个下拉状态,如...

 DropDown {

                enabled: true
                // text only
                Option {
                    text: "EUR/USD"

                }

            }

我的数据库基础读取功能就像......     QList DatabaseOperations :: readRecords(QString tableName){

QList<QString> sym_ID_List;
  // 1. Get the local DB connection. Note, called database()
  //    Will automatically open a connection to the database
     QSqlDatabase database = QSqlDatabase::database(); // opens the default database.

  // 2. Create a query to search for the records
     QSqlQuery query(database);
     const QString sqlQuery = "SELECT * FROM "+tableName;

     if (query.exec(sqlQuery)) {

         // Get the field indexes. We know the order of the fields, and could skip this step.
         // However this will still work if the fi changeldse order in the query string.
         const int customerIDField = query.record().indexOf("SymbolId");

         // 3. Start navigating through the records by calling the 'next' function.
        //     When there are no longer any records it will return false.
         int recordsRead = 0;
         while (query.next()) {
             // 4. Access the data (stored in the query) via the field indexes
             //    and add the data to the model.

                sym_ID_List.insert(recordsRead,query.value(1).toString());


             recordsRead++;
         }
         qDebug() << "Read " << recordsRead << " records succeeded";
         if (recordsRead == 0) {
            // alert(tr("The customer table is empty."));
         }
     } else {
        // alert(tr("Read records failed: %1").arg(query.lastError().text()));
     }

     // 6. Optionally close the database connection if we no longer plan to use it
     database.close();
     return sym_ID_List;

}

一次......这个方法即执行,它返回“Qlist”中的所有符号ID。现在我的问题是如何将这些“Qlist”元素dynamiccaly添加到Drop Down?

如何实现它,

谢谢,

1 个答案:

答案 0 :(得分:0)

那么,您需要做的第一件事就是将您的QML Dropdown暴露给C ++。这是通过对象名称属性ala:

完成的
DropDown {
    objectName: "myDropDown"
    Option {
        text: "EUR/USD"
    }
}

接下来,从C ++中找到这个孩子:

QmlDocument *qml =  QmlDocument::create("asset:///my.qml");
Container *root = qml->createRootObject<bb::cascades::Container>(); //or whatever the root control is
DropDown *dropDown = root->findChild<DropDown*>("myDropDown");

最后,添加QList中的选项:

foreach (QString string, list) {
    dropDown->add(Option::create().text(list));
}