Results 1 to 4 of 4

Thread: Problems with custom model and rowsInserted() signal

  1. #1
    Join Date
    Nov 2010
    Posts
    22
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Problems with custom model and rowsInserted() signal

    Hi everybody,

    I am having a problem with a custom model. I started with a code where a QTreeView was connected to a customized QStandardItemModel. Everything worked great until an idiot (me) wanted to implement a custom proxy from QAbstractProxyModel and messed things up.

    In order to get the new insertions from the model, I connected the rowsInserted() signal:

    Qt Code:
    1. TreeProxy::TreeProxy ( QStandardItemModel * parent ) :
    2. {
    3. setSourceModel( parent );
    4.  
    5. bool ok;
    6. ok = connect( sourceModel(),
    7. SIGNAL (rowsInserted ( const QModelIndex & , int , int ) ),
    8. this,
    9. SLOT (slot_inserted_rows_for_my_proxy ( const QModelIndex & , int , int ) ));
    10. Q_ASSERT(ok)
    To copy to clipboard, switch view to plain text mode 

    The first thing I noticed was that the model was not sending the rowsInserted() although the view receives new insertions with no problem at all. The model inherits from QStandardItemModel not from QAbstractItemModel and it does not reimplement appendRow()/insertRow() so I would expect the signal to be OK

    I noticed that the proxy receives the signal doing this:

    Qt Code:
    1. beginInsertRows(
    2. indexFromItem(parent),
    3. indexFromItem(child_node).row(),
    4. indexFromItem(child_node).row()
    5. );
    6. parent->appendRow(child_node);
    7. endInsertRows();
    To copy to clipboard, switch view to plain text mode 

    But I would expect the begin/end stuff to be done inside the inherited implementation of appendRow. With that the proxy works and the view fails (blank)

    My only solution so far was redeclaring rowsInserted() as a public signal and emit it manually. According the documentation and other questions in this forum, I must not do this. So I wonder what I am doing wrong? What else do I have to do to synchronize a custom proxy and a custom model that inherits a full model implementation?

    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems with custom model and rowsInserted() signal

    Is the problem about insertions to the proxy not propagating to the source or the other way round?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2010
    Posts
    22
    Thanks
    8
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problems with custom model and rowsInserted() signal

    it is from the model insertions not propagating to the proxy

    My expectation is that calling insertRow() or appendRow() from a derived model from QStandardItemModel that does not re-implement those functions, should raise the rowsInserted() signal

    should it be like that? For me it seems strange to wrap around appendRow() the begin/end insert rows.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Problems with custom model and rowsInserted() signal

    The signal is emitted. At least according to the source code

    Qt Code:
    1. if (model)
    2. model->d_func()->rowsInserted(q, row, count);
    To copy to clipboard, switch view to plain text mode 
    rowsInserted() calls endInsertRows() which emits the signal.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 9
    Last Post: 14th February 2013, 19:39
  2. Custom Model and Proxy Model
    By frank100 in forum Qt Programming
    Replies: 1
    Last Post: 20th December 2010, 14:30
  3. Replies: 0
    Last Post: 19th July 2010, 08:48
  4. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 20:23
  5. Replies: 0
    Last Post: 1st February 2010, 11:00

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.