there are 1000 record in my database table,but when i use querymodel binding the tableview, there are 1000 records displaying in the tableview,but the querymodel.rowcount() return 256,why?thanks! the code as follows:
QString querystr
= "select * from mytable";
query.exec();
model->setQuery(query);
model->setHeaderData(1, Qt::Horizontal, tr("name"));
model->setHeaderData(2, Qt::Horizontal, tr("age"));
ui->tableViewZDCommTask->setModel(model);
ui->tableViewZDCommTask->setColumnHidden(0,true);
ui->tableViewZDCommTask->resizeColumnsToContents();
QHeaderView *header
= ui
->tableViewZDCommTask
->horizontalHeader
();
header->setStretchLastSection(true);
ui->tableViewZDCommTask->show();
QSqlQueryModel *model= new QSqlQueryModel;
QSqlQuery query;
QString querystr = "select * from mytable";
query.exec();
model->setQuery(query);
model->setHeaderData(1, Qt::Horizontal, tr("name"));
model->setHeaderData(2, Qt::Horizontal, tr("age"));
ui->tableViewZDCommTask->setModel(model);
ui->tableViewZDCommTask->setSelectionMode(QAbstractItemView::MultiSelection);
ui->tableViewZDCommTask->setSelectionBehavior(QAbstractItemView::SelectRows);
ui->tableViewZDCommTask->setColumnHidden(0,true);
ui->tableViewZDCommTask->resizeColumnsToContents();
ui->tableViewZDCommTask->setEditTriggers(QAbstractItemView::NoEditTriggers);
QHeaderView *header = ui->tableViewZDCommTask->horizontalHeader();
header->setStretchLastSection(true);
ui->tableViewZDCommTask->show();
QMessageBox::about(0,"",QString::number(model->rowCount()));//return 256[/INDENT]
To copy to clipboard, switch view to plain text mode
Bookmarks