El jue, 17-06-2010 a las 14:15 +0200, Przemek escribió:
> Hello,
> Is it possible to create in QtDesigner a form in combo box and insert sql 
> values in combo box later (during using application)?
> If yes, how to make it?
> 
> PZ 
> 
> 
> _______________________________________________
> Qt-creator mailing list
> [email protected]
> http://lists.trolltech.com/mailman/listinfo/qt-creator

* Before making any query you should have a database object with an
opened database connection:

QSqlDatabase db = QSqlDatabase::::addDatabase("QSQLITE");
db.open("myDB.sqlite"); // You should check the return value

* Now execute the query:

QSqlQuery query("SELECT Name FROM People");

* Clean any content in the combo box:

ui->comboBox->clear();

* Iterate through the results and add each name to the combo box:

while(query.next())
    ui->comboBox->addItem( query.values(0).toString() );

And that's it.


Participe en la 15 Convención Científica de Ingeniería y Arquitectura, del 29 
de noviembre al 3 de diciembre de 2010
La Ingeniería y la Arquitectura por un Futuro Sustentable

Palacio de Convenciones, La Habana, Cuba
http://www.cujae.edu.cu/eventos/convencion 
_______________________________________________
Qt-creator mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-creator

Reply via email to