QSqlRelationalTableModel query question
Hi,
I'm currently busy with a SQLite database, and I have a question.
I have two tables, clients and orders, the orders table has to be populated in the QSqlRelationalTableModel. But the client information has to be added to the row.
So the first thing I did was is setRelation(clientId, "cid", "First Name"); (with clientId as columnIndex from the orders table) and it works, but I need more client information than the first name.
How can I solve such a problem?
Kind regards,
Marcel Boersma
Re: QSqlRelationalTableModel query question
I've found a solution, right now I'm using a QSqlQueryModel so I can combine some queries.
But now I have another problem(A)
Some code snippets:
Code:
mainWindow
::mainWindow(QWidget *parent
){ //create model
//setQueryCritics
this->setQueryCritics(orderModel, 1);
}
{
query.prepare("SELECT c.*, o.* FROM clients AS c, orders AS o WHERE o.oid = c.cid and o.currentStatus = :status ");
switch(type){
case 1 :
//orderModel
query.bindValue(":status", "1");
break;
case 2 :
//finishModel
query.bindValue(":status", "2");
break;
case 3 :
//trashModel
query.bindValue(":status", "3");
break;
case 4 :
//clientModel
query.prepare("SELECT * FROM clients");
break;
}
model.setQuery(query);
}
and here is the error message I get:
Quote:
mainWindow.cpp:37: error: no matching function for call to 'mainWindow::setQueryCritics(QSqlQueryModel*&, int)'
I hope and I think it's a real simple problem, but I don't see the solution :(
Can somebody help me with this?
Kind regards,
Cyberboy
Re: QSqlRelationalTableModel query question
Your function takes a reference but you try to pass a pointer.
Re: QSqlRelationalTableModel query question
all-right, how can I edit the query of the model I pass in the function?
Do I have to pass a pointer or a reference?
Re: QSqlRelationalTableModel query question
Well, this is a basic C++ issue, but let's say that you might want to alter the function to take a pointer...