Hi,
i want to get value from selected table row (getting it's index) and get the record in first column from this record.
In accordance with documentation of QT it should be like this:
QModelIndexList selectedList = ui->tableView_clients->selectionModel()->selectedRows();
int selected_row;
for( int i=0; i<selectedList.count(); i++)
//QMessageBox::information(this,"", QString::number(selectedList.at(i).row()));
selected_row=selectedList.at(i).row();
mod.setQuery("SELECT * FROM clients");
int ClientId = mod.data(mod.index(selected_row, 1)).toInt();
emit selectedRaw
(QString::number(ClientId
));
QModelIndexList selectedList = ui->tableView_clients->selectionModel()->selectedRows();
QSqlQueryModel mod;
int selected_row;
for( int i=0; i<selectedList.count(); i++)
//QMessageBox::information(this,"", QString::number(selectedList.at(i).row()));
selected_row=selectedList.at(i).row();
mod.setQuery("SELECT * FROM clients");
int ClientId = mod.data(mod.index(selected_row, 1)).toInt();
emit selectedRaw(QString::number(ClientId));
To copy to clipboard, switch view to plain text mode
It doesn't display error but simply doesn't get the data i need.Instead every time i get 0.
Bookmarks