[Qt-interest] QTableView: How can I get the data of selected row.
Mhayk Whandson
eu at mhayk.com.br
Fri May 15 16:32:18 CEST 2009
Hello Mildred,
I would like to get a one specific cell in the row. I use this solution:
{
QVariant variant
QModelIndex index;
int rownumber;
QSqlQuery *query = new QSqlQuery;
index = group_ui->tableView->currentIndex();
rownumber = index.row();
index = index.sibling(rownumber, 0); /* 0 is the code of id column */
variant = index.data();
query->prepare("delete from dsm_group where id = ?");
query->addBindValue(variant.toString());
query->exec();
refrashTableView();
}
How you can see I use the method sibling that I can specific the row
and column. Did you understand ?
best regards,
On Thu, May 14, 2009 at 10:16 PM, Mildred Ki'Lya
<ml.mildred593 at gmail.com> wrote:
> On 05/12/2009 09:14 PM, Mhayk Whandson wrote:
>>
>> Hi all, I am tryng to get the datas of a one selected row. I would
>> like to get all columns about this selected row. Example:
>>
>> ____ _________________ __________
>> | ID | Name | Age |
>> ---- ----------------- ----------
>> | 1 | Mhayk Whandson | 22 |
>> ---- ----------------- ----------
>>
>> So, I would like get all datas in these row(id, name, age). Could you help
>> me ?
>>
>>
>
> Well, I don't really understand what you're trying to do.
> If you want to get all the data from a row, just do something like
>
> QModelIndex idx = ... ;
> int nbcols = idx->model()->columnCount();
> for(int i = 0; i < nbcols; ++i) {
> QModelIndex idx2 = idx->model()->index(idx->row(), i);
> QVariant cell = idx->model()->data(idx2, role);
> // do something with the QVariant
> }
>
>
> --
> Mildred Ki'Lya
> ╭───────── mildred593@online.fr ──────────
> │ Jabber, GoogleTalk:<mildred at jabber.fr>
> │ Website:<http://ki.lya.online.fr> GPG ID: 9A7D 2E2B
> │ Fingerprint: 197C A7E6 645B 4299 6D37 684B 6F9D A8D6 9A7D 2E2B
>
>
--
Mhayk Whandson
Linux User #413723
E-mail: eu at mhayk.com.br
More information about the Qt-interest-old
mailing list