Results 1 to 6 of 6

Thread: Error with QSqlQueryModel(setQuery)

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Error with QSqlQueryModel(setQuery)

    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.


    Qt Code:
    1. QString search = "SELECT sname, ssurname, sidcard, dtdob, id FROM users WHERE iaccesslevel=:iaccesslevel AND (id=:id0 OR id = :id1)";
    2.  
    3.  
    4. QSqlQuery myquery(*m_pI->m_pUsersDB->GetDBPtr());
    5. myquery.prepare(search);
    6. myquery.bindValue(":iaccesslevel", 1);
    7. myquery.bindValue(":id0", 14); //For instance, id = 14
    8. myquery.bindValue(":id1", 15);
    9. alumnosFiltrados.exec();
    10.  
    11.  
    12. m_pI->m_pQueryModel->setQuery(myquery);
    13. m_pI->m_pQueryModel->setHeaderData(0, Qt::Horizontal, tr("Nombre") );
    14. m_pI->m_pQueryModel->setHeaderData(1, Qt::Horizontal, tr("Apellidos") );
    15. m_pI->m_pQueryModel->setHeaderData(2, Qt::Horizontal, tr("NIF") );
    16. m_pI->m_pQueryModel->setHeaderData(3, Qt::Horizontal, tr("Fecha Nacimiento") );
    17. ui.my_tableView->setModel(m_pI->m_pQueryModel);
    18.  
    19.  
    20. ui. my_tableView->setColumnHidden(4, true);
    To copy to clipboard, switch view to plain text mode 

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error with QSqlQueryModel(setQuery)

    You have an invalid pointer somewhere. Probably here: m_pI->m_pQueryModel
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    jano_alex_es (8th May 2009)

  4. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Error with QSqlQueryModel(setQuery)[SOLVED]

    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.
    Last edited by jano_alex_es; 8th May 2009 at 09:27.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Error with QSqlQueryModel(setQuery)

    Does the model pointed by this variable have a parent? If so, what is it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Error with QSqlQueryModel(setQuery)

    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

  7. #6
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: Error with QSqlQueryModel(setQuery)

    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!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.