Results 1 to 5 of 5

Thread: Database and QSqlRelationalTableModel problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2007
    Location
    Munich
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Database and QSqlRelationalTableModel problem

    Are you calling select() on your model? setTableName() only populates the headers, but does not execute a query to fetch the data.

    Also:

    m_pTableRecord=&pDatabase->m_Database.record(sTableName); // fetches column names

    this line is scary - you are taking the address of a temporary object. m_pTableRecord becomes a dangling pointer!

  2. #2
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Database and QSqlRelationalTableModel problem

    Quote Originally Posted by harryf View Post
    Are you calling select() on your model? setTableName() only populates the headers, but does not execute a query to fetch the data.

    Also:

    m_pTableRecord=&pDatabase->m_Database.record(sTableName); // fetches column names

    this line is scary - you are taking the address of a temporary object. m_pTableRecord becomes a dangling pointer!
    I am dealing with this line right now, marcel helped me a lot with it. But for now, I've chcked, column names are fetched correctly. I will check now for select() method execution. Thanks a lot for now.
    Qt 5.3 Opensource & Creator 3.1.2

  3. #3
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Database and QSqlRelationalTableModel problem [SOLVED]

    I finally solved the problem, I had m_pModel on two different places (in CDatabaseFoundation and in CBrowserWindow). I've deleted the one in CBrowserWindow and works fine. For future references, what do you think, where should be m_pModel (QSqlRelationTableModel) declared in class that handles database connection or in class that handles record browsing?
    Qt 5.3 Opensource & Creator 3.1.2

  4. #4
    Join Date
    Jun 2007
    Location
    Munich
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Database and QSqlRelationalTableModel problem

    A database model encapsulates a result set sent from the database. I would always keep it as local as possible (in your case, in the record browsing class) to prevent concurrency errors (e.g. when refactoring, two views might end up accessing the same model leading to strange race conditions).

Similar Threads

  1. Threads and database connection
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 7th August 2013, 08:30
  2. [QMYSQL] connection problem
    By chaos_theory in forum Installation and Deployment
    Replies: 5
    Last Post: 2nd July 2007, 09:52
  3. problem in doing database program
    By wei243 in forum Qt Programming
    Replies: 0
    Last Post: 4th April 2007, 12:01
  4. Oracle Database Problem
    By magikalpnoi in forum Qt Programming
    Replies: 3
    Last Post: 27th September 2006, 21:19
  5. Filling combobox from database
    By Philip_Anselmo in forum Qt Programming
    Replies: 3
    Last Post: 11th May 2006, 17:53

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.