Results 1 to 20 of 20

Thread: beginInsertRows doesn't appear to be working?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: beginInsertRows doesn't appear to be working?

    Does DATreeModel::setCanData() get called only once or many times? I think you might be looking for something like this:
    Qt Code:
    1. void DATreeModel::setCanData( CANDATA *pData, int nAmount, int nCount )
    2. {
    3. if( pData )
    4. {
    5. int row = rowCount();
    6. beginInsertRows(QModelIndex(), row, row + nAmount - 1);
    7. ...
    8. endInsertRows();
    9. }
    10. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  2. #2
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: beginInsertRows doesn't appear to be working?

    Hi,

    setCanData() gets called over and over again from another thread. I tried what you suggested and still the data is not displayed until I click on the table view, also, the rowCount() function still not updating the tableview row amount?

    Unless I do something like return 10000 or whatever from the rowCount function, no rows are inserted, I thought rowCount() would do this for you?

    Kind regards,
    Steve

  3. #3
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: beginInsertRows doesn't appear to be working?

    I'm still struggling with this, the rowCount returns the amount of rows, but the view doesn't reflect this?

    Also, QModelIndex() seems to have invalid row and column values in my beginInsertRows...

    Can't believe how difficult this is proving for something so trivial!

    Regards,
    Steve

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

    Default Re: beginInsertRows doesn't appear to be working?

    You can't do it from another thread. Containers are not thread safe. You can only emit a signal from the other thread and catch it in the model and update the model from within the main thread.

  5. #5
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: beginInsertRows doesn't appear to be working?

    Sorry, the worker thread just reads data and emits a signal to main gui thread which then informs the model to update its data. The code below shows the code within the main gui which informs the model of the change with the setCanData function:


    Qt Code:
    1. if( m_pCanReadThread->isRunning() ) // user may have stopped thread
    2. {
    3. if( nCount < 8000 )
    4. {
    5. m_ptreeModel->setCanData( pData, nAmount, nCount );
    6. QModelIndex index = m_ptreeModel->index( nCount, 0 );
    7. ui.tableView->scrollTo( index );
    8. }
    9. else
    10. {
    11. m_pCanReadThread->cancelThread();
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Steve

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

    Default Re: beginInsertRows doesn't appear to be working?

    As a little check emit layoutChanged() at the end of setCanData(). If it makes it work, it means that you have something wrong in your model and using the Modeltest might be a good idea.

  7. #7
    Join Date
    May 2007
    Posts
    301
    Thanks
    46
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: beginInsertRows doesn't appear to be working?

    Hi,

    emit layoutChanged() doesn't have any effect. Still not refreshing the view nor are the rows being inserted.

    The only way I can get this to work is to set the row count to a big size right at the begining and click on the table view to get the items to appear, very, very strange and totally not acceptable. Obviously when the table has to scroll, the items appear. One thing I have noticed is that the items in the first column of the table always appear?

    Regards,
    Steve

Similar Threads

  1. QTextEdit::find() backward not working
    By sukanyarn in forum Qt Programming
    Replies: 1
    Last Post: 15th November 2006, 19:33
  2. Replies: 1
    Last Post: 11th June 2006, 22:25
  3. Mac OS X UI not working
    By hvengel in forum Qt Programming
    Replies: 3
    Last Post: 1st April 2006, 01:02
  4. Signals/Slots stopped working
    By Jimmy2775 in forum Qt Programming
    Replies: 8
    Last Post: 31st March 2006, 21:11
  5. QSettings - beginReadArray not working
    By Mike in forum Qt Programming
    Replies: 7
    Last Post: 9th January 2006, 21:24

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.