blackberry 10 - Add elements to Drop down bb 10 cascades -
i have drop down in qml file like...
dropdown { enabled: true // text option { text: "eur/usd" } }
and database base read function like... qlist databaseoperations::readrecords(qstring tablename){
qlist<qstring> sym_id_list; // 1. local db connection. note, called database() // automatically open connection database qsqldatabase database = qsqldatabase::database(); // opens default database. // 2. create query search records qsqlquery query(database); const qstring sqlquery = "select * "+tablename; if (query.exec(sqlquery)) { // field indexes. know order of fields, , skip step. // still work if fi changeldse order in query string. const int customeridfield = query.record().indexof("symbolid"); // 3. start navigating through records calling 'next' function. // when there no longer records return false. int recordsread = 0; while (query.next()) { // 4. access data (stored in query) via field indexes // , add data model. sym_id_list.insert(recordsread,query.value(1).tostring()); recordsread++; } qdebug() << "read " << recordsread << " records succeeded"; if (recordsread == 0) { // alert(tr("the customer table empty.")); } } else { // alert(tr("read records failed: %1").arg(query.lasterror().text())); } // 6. optionally close database connection if no longer plan use database.close(); return sym_id_list;
}
once...this method ie executed, returns symbol id's in "qlist". question how add these "qlist" elements dynamiccaly drop down?
how achive it,
thanks,
well, first thing need expose qml dropdown c++. done object name property ala:
dropdown { objectname: "mydropdown" option { text: "eur/usd" } }
next, find child c++:
qmldocument *qml = qmldocument::create("asset:///my.qml"); container *root = qml->createrootobject<bb::cascades::container>(); //or whatever root control dropdown *dropdown = root->findchild<dropdown*>("mydropdown");
finally, add options qlist:
foreach (qstring string, list) { dropdown->add(option::create().text(list)); }
Comments
Post a Comment