PDA

View Full Version : QSqlRelationalTableModel query question



cyberboy
4th February 2008, 19:08
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

cyberboy
6th February 2008, 18:17
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:



mainWindow::mainWindow(QWidget *parent){
//create model
QSqlQueryModel *orderModel = new QSqlQueryModel;

//setQueryCritics
this->setQueryCritics(orderModel, 1);
}

void mainWindow::setQueryCritics(QSqlQueryModel &model, int type)
{

QSqlQuery query;
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:


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

jpn
6th February 2008, 18:21
Your function takes a reference but you try to pass a pointer.

cyberboy
6th February 2008, 18:24
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?

jpn
6th February 2008, 18:47
Well, this is a basic C++ issue, but let's say that you might want to alter the function to take a pointer...