Results 1 to 10 of 10

Thread: QTableView from SQLite, empty!

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Lightbulb Re: QTableView from SQLite, empty!

    Quote Originally Posted by jacek View Post
    You create the model on the stack, so it gets destroyed as soon as it goes out of scope, leaving a dangling pointer behind. Better create that model on the heap (i.e. using the new operator).
    Yeah, it works now... so I guess you have to follow the following (undocumented) rules:

    1) You must create your database connection before you create your (QSqlRelatinoalTableModel) model.
    2) You must create your QSqlRelationalTableModel object on the heap, using the 'new' operator.

    Did I miss anything?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView from SQLite, empty!

    Quote Originally Posted by grellsworth View Post
    2) You must create your QSqlRelationalTableModel object on the heap, using the 'new' operator.
    Not exactly. You can create it on the stack, but you must make sure it exists long enough.

  3. #3
    Join Date
    Jul 2007
    Posts
    27
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QTableView from SQLite, empty!

    OK, so it should be:

    2) Make sure your QSqlRelationalTableModel object doesn't go out of scope.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTableView from SQLite, empty!

    Quote Originally Posted by grellsworth View Post
    OK, so it should be:

    2) Make sure your QSqlRelationalTableModel object doesn't go out of scope.
    Yes, but this isn't something that must be documented.

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.