Results 1 to 5 of 5

Thread: using QSqlRelationalTableModel opposite of the example

  1. #1
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question using QSqlRelationalTableModel opposite of the example

    I am new to using QSql classes, been a few years since I have done any Qt programming, actually. My model:

    Table: PriceList
    Fields: PriceListId, Name

    1 ...* to

    Table: ProductItem
    Fields: ProductItemId, PriceListId, ...

    The ProductItem table has a foreign key (PriceListId) to the PriceList table.

    I have a ComboBox who's model is the PriceList model. There is a TableView under it, when a different PriceList is selected, I want the TableView to update. How do I wire up the QSqlRelationalTableModel?

    Sam

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: using QSqlRelationalTableModel opposite of the example

    Have you considered attaching the QTableView to a QSortFilterProxyModel model (overlaid on your product item model) and using the QComboBox::currentIndexChanged() signal to change the filtering on the proxy model for the foreign key column?

  3. #3
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: using QSqlRelationalTableModel opposite of the example

    Sorry it took me a few days to get back to you, been swamped...

    I just read over QSortFilterProxyModel model and it isn't looking like the solution. I just realized what I am really looking for, an example of how to implement Master/Detail with the Model View. The PriceList is the master, in a comboBox, the ProductList is the details in the TableView.

    Sam

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: using QSqlRelationalTableModel opposite of the example

    I think that it is exactly the solution. Take a look at the Basic Sort/Filter Model and Address Book Example in the docs. In the Basic example imagine that your combo box replaces the "Filter Pattern" text box and the the Sorted/Filter table view is your detail panel.
    Last edited by ChrisW67; 8th June 2010 at 04:46. Reason: updated contents: view not model

  5. #5
    Join Date
    Jun 2010
    Location
    Salatiga, Indonesia
    Posts
    160
    Thanks
    11
    Thanked 32 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    1

    Default Re: using QSqlRelationalTableModel opposite of the example

    You can update your QRelationalTableModel by using QSqlRelationalTableModel::setFilter()

    for example:

    Qt Code:
    1. void Widget::priceListIndexChanged(int index)
    2. {
    3. int priceListId = priceListModel->index(index, 0).data(Qt::DisplayRole).toInt();
    4. productModel->setFilter(QString("%1.pricelistid=%2").arg(productModel->tableName()).arg(priceListId));
    5. productModel->select();
    6. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Problems with QSqlRelationalTableModel
    By waldo1979 in forum Qt Programming
    Replies: 4
    Last Post: 5th January 2014, 01:12
  2. Opposite of |= operation
    By JPNaude in forum Qt Programming
    Replies: 5
    Last Post: 16th November 2009, 12:33
  3. QSqlRelationalTableModel
    By marvin in forum Newbie
    Replies: 2
    Last Post: 19th November 2008, 21:29
  4. how to add sub table to QSqlRelationalTableModel
    By SunnySan in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2008, 11:05
  5. QSqlRelationalTableModel
    By jjay in forum Qt Programming
    Replies: 1
    Last Post: 20th February 2008, 15:20

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.