Re: [Qt-creator] Combo Box with sql values

2010-06-21 Thread Sergio de la Cruz Rodriguez
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
> Qt-creator@trolltech.com
> 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 = QSqlDatabaseaddDatabase("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
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator


Re: [Qt-creator] Combo Box with sql values

2010-06-17 Thread Coda Highland
Absolutely. It would be a little silly if you couldn't access UI
elements from your source code. ;) Just make sure to give the combo
box a sensible object name, and then refer to the QComboBox
documentation for how to manipulate it by that pointer.

/s/ Adam

On Thu, Jun 17, 2010 at 7:15 AM, Przemek  wrote:
> 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
> Qt-creator@trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-creator
>
___
Qt-creator mailing list
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator


[Qt-creator] Combo Box with sql values

2010-06-17 Thread Przemek
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
Qt-creator@trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-creator