Hi All,
I have a little problem with my QtCode, perhaps u guys can help me to solve the problem and I'll very appreciate. In my code, I aim to put an empty code to the QTableView whereas the query is get from QSqlQueryModel. I tried with sqlQueryModel->insertRow(0);, but nothing happend in the table. Completely the code looks like this
Qt Code:
  1. sqlQueryModel->setQuery("SELECT * FROM x=a, y=b where b.ID = 0AND (b.anotherid = a.anotherid )",sqlDatabase);
  2. sqlQueryModel->setHeaderData(0,Qt::Horizontal,tr("1"));
  3. sqlQueryModel->setHeaderData(1,Qt::Horizontal,tr("2"));
  4. sqlQueryModel->setHeaderData(2,Qt::Horizontal,tr("3"));
  5.  
  6. ui->tableView->setModel(sqlQueryModel );
  7. ui->tableView->setSelectionMode(QAbstractItemView::SingleSelection);
  8. ui->tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
  9. ui->tableView->resizeColumnsToContents(); // resize column width depend to data cell
  10. ui->tableView->setEditTriggers(QAbstractItemView::NoEditTriggers); //unable edit through the cell
  11. ui->tableView->verticalHeader()->setHidden(true);
  12. ui->tableView->selectRow(0);
  13.  
  14. header = ui->tableView->horizontalHeader();
  15. header->setResizeMode(QHeaderView::Stretch);
  16.  
  17. sqlQueryModel->insertRow(0);
To copy to clipboard, switch view to plain text mode 

I hope it can describe what the problem is.
Thanks.