What I also discovered was that the sorting function in the table view doesn't work. Even when I had the sortingEnabled set to true.
Are those problems related to each other somehow?
Both cases have the same issue, it seems like they can't handle the data inside the tableview, whether it's refreshing the data or sorting the data.
Before I wrote the code to search the table view I wrote this to update the table view after new data was inserted into the database.
void mainWindow::updateTables(){
//set queries
this->setQueryCritics(orderModel, 1);
this->setQueryCritics(finishModel, 2);
this->setQueryCritics(trashModel, 3);
this->setQueryCritics(clientModel, 4);
//load in interface
this->interface->orderTable->setModel(orderModel);
this->interface->finishTable->setModel(finishModel);
this->interface->trashTable->setModel(trashModel);
this->interface->clientTable->setModel(clientModel);
}
void mainWindow::updateTables(){
//set queries
this->setQueryCritics(orderModel, 1);
this->setQueryCritics(finishModel, 2);
this->setQueryCritics(trashModel, 3);
this->setQueryCritics(clientModel, 4);
//load in interface
this->interface->orderTable->setModel(orderModel);
this->interface->finishTable->setModel(finishModel);
this->interface->trashTable->setModel(trashModel);
this->interface->clientTable->setModel(clientModel);
}
To copy to clipboard, switch view to plain text mode
{
switch(type){
case 1 :
//orderModel
model->setQuery("SELECT c.*, o.* FROM clients AS c, orders AS o WHERE o.cid = c.cid and o.currentStatus = 1 ");
break;
case 2 :
//finishModel
model->setQuery("SELECT c.*, o.* FROM clients AS c, orders AS o WHERE o.cid = c.cid and o.currentStatus = 2 ");
break;
case 3 :
//trashModel
model->setQuery("SELECT c.*, o.* FROM clients AS c, orders AS o WHERE o.cid = c.cid and o.currentStatus = 3 ");
break;
case 4 :
//clientModel
model->setQuery("SELECT * FROM clients");
break;
}
}
void mainWindow::setQueryCritics(QSqlQueryModel *model, int type)
{
switch(type){
case 1 :
//orderModel
model->setQuery("SELECT c.*, o.* FROM clients AS c, orders AS o WHERE o.cid = c.cid and o.currentStatus = 1 ");
break;
case 2 :
//finishModel
model->setQuery("SELECT c.*, o.* FROM clients AS c, orders AS o WHERE o.cid = c.cid and o.currentStatus = 2 ");
break;
case 3 :
//trashModel
model->setQuery("SELECT c.*, o.* FROM clients AS c, orders AS o WHERE o.cid = c.cid and o.currentStatus = 3 ");
break;
case 4 :
//clientModel
model->setQuery("SELECT * FROM clients");
break;
}
}
To copy to clipboard, switch view to plain text mode
And that one does work!
Bookmarks