Results 1 to 2 of 2

Thread: ProxyModel problem

  1. #1
    Join Date
    May 2009
    Location
    USA
    Posts
    300
    Thanks
    82
    Thanked 11 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default ProxyModel problem

    I need to relate the view index to the model index for searches in the view.
    Based the model index on the database table primary key.
    Not sure I understand the proxy model doc, but,
    here is what I tried:

    Qt Code:
    1. QModelIndex midx = model->index(id, 0, QModelIndex());
    2. qDebug() << " midx is " << midx;
    3. QModelIndex vidx = proxy->mapFromSource(midx);
    4. qDebug() << " vidx is " << vidx;
    To copy to clipboard, switch view to plain text mode 

    midx has the correct value for the row in the model/database.
    vidx is -1 The error says index from wrong model passed to mapFromSource.
    What's wrong?
    Last edited by waynew; 14th February 2010 at 01:21.

  2. #2
    Join Date
    Nov 2009
    Posts
    129
    Thanks
    4
    Thanked 29 Times in 29 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ProxyModel problem

    The constructor for QSortFilterProxyModel doesn’t set the source model; it sets the QObject that owns the proxy model. (You can let that default to null if you will delete the proxy model yourself.) You have to use QSortFilterProxyModel::setSourceModel to set the source model.

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

    waynew (14th February 2010)

Similar Threads

  1. Sharing Selections between Model and ProxyModel
    By mentat in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2010, 17:31
  2. ProxyModel and ItemDelegate work togather?
    By litterflybug in forum Qt Programming
    Replies: 0
    Last Post: 15th December 2009, 02:28
  3. Replies: 2
    Last Post: 6th January 2009, 20:55

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.