PDA

View Full Version : Error with QSqlQueryModel(setQuery)



jano_alex_es
7th May 2009, 17:01
Hi,

I'm having a lot of problems (Unhandled exception at 0x00b9b66d in UsersApp.exe: 0xC0000005: Access violation reading location 0xcdcd024d.) the second time I execute setQuery().

I tried with "clear()", before, but another similar error pops.




QString search = "SELECT sname, ssurname, sidcard, dtdob, id FROM users WHERE iaccesslevel=:iaccesslevel AND (id=:id0 OR id = :id1)";


QSqlQuery myquery(*m_pI->m_pUsersDB->GetDBPtr());
myquery.prepare(search);
myquery.bindValue(":iaccesslevel", 1);
myquery.bindValue(":id0", 14); //For instance, id = 14
myquery.bindValue(":id1", 15);
alumnosFiltrados.exec();


m_pI->m_pQueryModel->setQuery(myquery);
m_pI->m_pQueryModel->setHeaderData(0, Qt::Horizontal, tr("Nombre") );
m_pI->m_pQueryModel->setHeaderData(1, Qt::Horizontal, tr("Apellidos") );
m_pI->m_pQueryModel->setHeaderData(2, Qt::Horizontal, tr("NIF") );
m_pI->m_pQueryModel->setHeaderData(3, Qt::Horizontal, tr("Fecha Nacimiento") );
ui.my_tableView->setModel(m_pI->m_pQueryModel);


ui. my_tableView->setColumnHidden(4, true);



the first time works perfectly... but when the code is called again it stops after "m_pI->m_pQueryModel->setQuery(myquery);"

how this could be? is the query "broken" somehow?

thanks!

wysota
7th May 2009, 17:15
You have an invalid pointer somewhere. Probably here: m_pI->m_pQueryModel

jano_alex_es
8th May 2009, 08:15
Mmmh... doesn't seem so. That pointer is not used anywhere else and it doesn't change at all during the application.

Actually, it works the first time, and also works fine in another similar code (mine shows some data and the other, the one which works always, shows all the data).

It's only the second time I try to execute this "show filtered data" function.

wysota
8th May 2009, 08:32
Does the model pointed by this variable have a parent? If so, what is it?

jano_alex_es
8th May 2009, 08:53
the model is inside an structure (where I keep my member variables) and has no parent.

That structure is not destroyed or changed at all.

Seems like the problem is with the SQLQuery

jano_alex_es
8th May 2009, 09:25
solved :)

The problem wasn't in this code... I started to follow my pointers (you seemed pretty sure when you said it was a pointer problem, so I assumed you were right and I had this problem somewhere) and the problem was when I created a new formular (QDialog); there, I reinitializate the databe and seems like I had to close it or they had some kind of compatibility problem.

I just send the database pointer trough the constructor, the database is not set up again in the new QDialog, and it works.

thanks!