0
我有一个QTableView填充QSqlQueryModel。我试图根据哪个RadioButton被选中来对表格排序,但是当我按下它们时没有任何事情发生。有一点我可以把它排序,但只有一次。我在这里做错了什么?Qt TableView只排序一次
void MainWindow::on_openButton_clicked()
{
QString filePath = ui->lineEdit->text();
if(filePath != ""){
if(openDB(filePath)){
ui->debugLabel->setText("Database opened");
MainWindow::populateTable();
}else{
ui->debugLabel->setText("Unable to open database");
}
} else {
ui->debugLabel->setText("Path is empty");
}
}
void MainWindow::populateTable(){
if(readDB()){
ui->tableView->setModel(toast.dbModel);
}
}
void MainWindow::on_shootButton_toggled(bool checked)
{
if(checked){
ui->tableView->sortByColumn(0);
}
}
void MainWindow::on_winButton_toggled(bool checked)
{
if(checked){
ui->tableView->sortByColumn(1);
}
}
bool openDB(QString path){
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(path);
return db.open();
}
bool readDB(){
if(db.isOpen()){
dbModel->setQuery("select * from test", db);
return true;
} else {
return false;
}
}