2014年1月5日星期日

[Android] QT - tableview how to get the contents of a cell ?

void gz :: on_pushButton_2_clicked ()
{
static QSqlQueryModel * model = new QSqlQueryModel (ui-> tableView);
model-> setQuery (QString ("select * from yggzinfo;"));
int column = model-> columnCount (); / / get the number of columns
int row = model-> rowCount (); / / get the number of rows
QModelIndex index = model-> index (column, row, QModelIndex ());
ui-> lineEdit-> setText (index);
}

------ Solution ------------------------------------ --------
your code less secure. I rewrote it:
void gz::on_pushButton_2_clicked()
{
    static QSqlQueryModel model(NULL);
    model.setQuery(QString("select * from yggzinfo;"));
    ui->tableView->setModel(&model);
    int column = ui->tableView->currentIndex().column(); //获得当前选中的列数
    int row = ui->tableView->currentIndex().row();       // 获得当前选中的行数
    //具体到你使用的model,有两种方式获取你想要的数据。最简单是
    QVariant currentData = model.data(ui->tableView->currentIndex());
    //或者通过record获取。
    QSqlRecord currentRecord=model.record(row);
    currentData = currentRecord.value(column);
    ui->lineEdit->setText(index);
}

int currentRow = ui-> tableView-> currentIndex () row ();.
------ eference ------------- -------------------------- signal

sent via response model ------ eference ----- ----------------------------------





There was an error 'index' was not declared in this scope
Great God seeking help , the end of major operations.
------ eference --------------------------------------- < br>
  
  
  
  
There was an error 'index' was not declared in this scope   
Great God seeking help , the end of major operations.  

ui-> lineEdit-> setText (currentData);
own debugging not know about the
------ eference ----------------------------- ----------
ui.lineEdit-> setText (. currentRecord.value (column) toString ());

himself tried it, so it should be
------ eference --------------------------- ------------
still did not get to

没有评论:

发表评论