[COLOR=#333333][FONT=monospace]QSqlQueryModel *tableViewModel = new QSqlQueryModel;
[/FONT][/COLOR][COLOR=#333333][FONT=monospace]tableViewModel->setQuery("SELECT piece_name, nn, status FROM main WHERE nn !='0' ORDER BY uid");
[/FONT][/COLOR][COLOR=#333333][FONT=monospace]tableViewModel->setHeaderData(0, Qt::Horizontal, "Piece Name");
[/FONT][/COLOR][COLOR=#333333][FONT=monospace]tableViewModel->setHeaderData(1, Qt::Horizontal, "NN");
[/FONT][/COLOR][COLOR=#333333][FONT=monospace]tableViewModel->setHeaderData(2, Qt::Horizontal, "Status");
[/FONT][/COLOR][COLOR=#333333][FONT=monospace]tableViewUi.tableView->setModel(tableViewModel);
[/FONT][/COLOR][COLOR=#333333][FONT=monospace]tableViewUi.tableView->resizeColumnsToContents();
[/FONT][/COLOR][COLOR=#333333][FONT=monospace]tableViewUi.tableView->setAlternatingRowColors(true);
[/FONT][/COLOR]
Veritabanında PHP ve java dışında hiç çalışmadım. MVC (Model view controller) yapısında olduğu için tablo modelini direkt alacaktır.
Kodlar size bir fikir vermiyorsa, yine de deneyin ve sorun olduğunda tekrar yazın lütfen.
Kaynak:
http://www.qtcentre.org/threads/10889-QTableView-and-MySQL