Results 1 to 3 of 3

Thread: Problem with QSqlRelationalTableModel and displaying the data

  1. #1

    Default Problem with QSqlRelationalTableModel and displaying the data

    Hey there,

    I've got an issue with QSqlRelationalTableModel. I have an PostgreSql database with some tables like Customer and other related stuff. In the table Customer i have foreign keys to other tables. But this keys are not always set with valid values. Now when i use QSqlRelationalTableModel->setRelation and execute the select method i dont get all the entrys in the table. Is there a way to get all the entrys with the select method even though not all foreign keys are set?

    I have thought of subclassing QSqlRelationalTableModel or QSqlQuery or QSqlTableModel is this the right approach or should i take a other way? The other Problem i've got is that the data which is stored in the model is more than i want to display. Is there a way to display only the collums i want? Lets assume the table customer has the collums firstname, lastname and age. Now i want the view that it only displays the firstname. The other values should be in the model but not visible to the user. How can i achieve this? Do i have to subclass the QAbstractItemView or is there another way? Maybe subclassing QSqlRelationalDelegate?

    I hope you can help me.

    Thanks in addvance

  2. #2

    Default Re: Problem with QSqlRelationalTableModel and displaying the data

    For second problem (I assume that you're using QTableView) the solution is to use hideColumn method:
    http://doc.qt.nokia.com/latest/qtabl...tml#hideColumn

  3. #3
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Problem with QSqlRelationalTableModel and displaying the data

    Bad news : QSqlRelationalTableModel is as is.
    Problem is with SQL query generated by QSqlRelationalTableModel. This query contains condition
    Qt Code:
    1. WHERE main_table_id = related_table_id
    To copy to clipboard, switch view to plain text mode 
    Of course when related_table_id is null the condition is false and result don't contains this records from main table. By me this is the biggest defect of QSqlRelationalTableModel. So You must create Yours own model starting from QAbstractTableModel or QSqlTableModel.

Similar Threads

  1. Replies: 2
    Last Post: 17th October 2010, 18:07
  2. Replies: 2
    Last Post: 8th August 2008, 01:54
  3. Problem in displaying RGB32 data
    By bmn in forum Qt Programming
    Replies: 2
    Last Post: 16th June 2008, 14:30
  4. Replies: 1
    Last Post: 7th July 2007, 08:41
  5. Table Model / View Problem -- Data Not Displaying
    By jhendersen in forum Qt Programming
    Replies: 1
    Last Post: 22nd April 2007, 06:45

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.