PDA

View Full Version : SQL select and use



cecchinoSMI
6th March 2014, 13:53
Hi to all,
I need a suggest to how design new code to implement an operation.
Starting from the fact that I'm able to use the querys fora a database using qt, I need a way to manage this data.

For example with this code:

this->model=new QSqlQueryModel();
model->setQuery("SELECT [DispositivoId],[Descrizione] FROM [IfaCOM].[dbo].[Dispositivo];");
ui->tableView->setModel(model);

I show the dataset present in the table "Dispositivo" in the tableView object.
Now I want to use the single values contained in the table for my personal porpouses.

How I can do it?

Thank you in advance.

anda_skoa
6th March 2014, 16:48
You can either get the values from the model, see methods index() and data() (or the data() method of the QModelIndex returned by index()), or you can run the query again usign QSqlQuery and work with its result.

Cheers,
_