Results 1 to 20 of 23

Thread: rowCount() is calling for all the top level items

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rowCount() is calling for all the top level items

    but when I test your new model I have seen all the top levels items rowsCount() is getting called, I am struggling exactly with this behavior only.

    Qt Code:
    1. int rowCount(const QModelIndex &parent = QModelIndex()) const
    2. {
    3. qDebug() << parent; //little change in debug msg
    4.  
    5. if(!parent.isValid()) return 10;
    6. if(parent.isValid() && !parent.parent().isValid()) return 2; // limit to two levels
    7.  
    8. return 0;
    9. }
    10.  
    11. int main(int argc, char **argv) {
    12. QApplication app(argc, argv);
    13. v.setFixedSize(200, 50); //set height to 50 so that view can accommodate 2 top level elements only
    14. Model model;
    15. v.setModel(&model);
    16. v.show();
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 
    The out put I observed is :

    QModelIndex(-1,-1,0x0,QObject(0x0) )
    QModelIndex(-1,-1,0x0,QObject(0x0) )
    QModelIndex(-1,-1,0x0,QObject(0x0) )
    QModelIndex(0,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(1,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(2,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(3,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(4,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(5,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(6,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(7,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(8,0,0xffffffff,QAbstractItemModel(0x28 fe18) )
    QModelIndex(9,0,0xffffffff,QAbstractItemModel(0x28 fe18) )

    //rowCount() is getting called for all top level items here.

    One more thing I have observed is, When i return 10000000(top level items) in rowCount() (in old model you suggested & in new model also), My application got crashed with runtime error (on Windows 8, 64bit application).
    And when I return 1000000 row count & when I try to scroll down its hanging like hell, not able to scroll at all.
    Last edited by prasad_N; 9th July 2015 at 07:01.
    Thanks :-)

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

    Default Re: rowCount() is calling for all the top level items

    Which Qt version are you using? How much RAM does your machine have?
    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
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rowCount() is calling for all the top level items

    I am using 4.8.6 & 5.4.0 with windows 8 and 4GB RAM, I tested on both the versions it failed.
    Thanks :-)

  4. #4
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rowCount() is calling for all the top level items

    Hi Any idea, why is this happening ?
    Thanks :-)

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

    Default Re: rowCount() is calling for all the top level items

    4E9 bytes for 1E7 items yields 4E2 (=400) bytes per item. My guess is you are running out of memory
    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.


  6. #6
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rowCount() is calling for all the top level items

    No I am not, It is taking around 128MB (for 10000000 top level items) && 28MB (for 1000000 top level items).
    still view is freezing like anything when I scroll, did you reproduce same when you pass more top level count.
    Thanks :-)

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

    Default Re: rowCount() is calling for all the top level items

    If you call setUniformRowHeights(true) then there is no such effect. I can scroll the view very quickly.

    By the way, I don't think you calculated the memory use correctly. For 10M top-level items with 2 child items each the application uses over 600MB for the data segment.
    Last edited by wysota; 10th July 2015 at 08:21.
    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.


  8. #8
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rowCount() is calling for all the top level items

    Quote Originally Posted by wysota View Post
    If you call setUniformRowHeights(true) then there is no such effect. I can scroll the view very quickly.
    - forgot to set setUniformRowHeights(true), Its working fine now

    - The only & main issue I have now is, rowCount() is still calling for all the top level items , Any idea how to prevent it.?

    By the way, I don't think you calculated the memory use correctly. For 10M top-level items with 2 child items each the application uses over 600MB for the data segment.
    Sorry I ran 32-bit application, It is taking around 280MB in a same case.
    Thanks :-)

  9. #9
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rowCount() is calling for all the top level items

    Hi Wysota,
    Did you find any solution for this (rowCount() is calling for all the top level items),
    I have observed one more thing that "Even for each mouse click on cell is calling rowCount() for all the top level items"
    I think this is the reason for my recent post - http://www.qtcentre.org/threads/6307...ure?highlight=

    what kind of optimizations we can do for both the problems.
    Thanks :-)

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

    Default Re: rowCount() is calling for all the top level items

    Why is that a problem that the framework calls rowCount() of every top-level item? Do you get noticable slowdowns because of that? The only "solution" I can see is to file a bug.
    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.


  11. #11
    Join Date
    Jun 2015
    Location
    India
    Posts
    185
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: rowCount() is calling for all the top level items

    Quote Originally Posted by wysota View Post
    Why is that a problem that the framework calls rowCount() of every top-level item? Do you get noticable slowdowns because of that? The only "solution" I can see is to file a bug.
    yes, There is a delay in populating data (I have populated 30 million rows with column count > 10).

    One more problem:
    And rowCount() is calling for all top level items when I emit headerDataChanged() signal which leads to further delay in selecting item & changing header.
    Item is not getting selected until header data changes. there is a considerable delay in changing header data after that only item is getting selected.
    my post related to this issue : http://www.qtcentre.org/threads/6307...ure?highlight=
    Thanks :-)

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

    Default Re: rowCount() is calling for all the top level items

    Quote Originally Posted by prasad_N View Post
    yes, There is a delay in populating data (I have populated 30 million rows with column count > 10).
    Maybe you can populate the model in batches? I think you could use canFetchMore() && fetchMore() for the invalid model index.

    One more problem:
    And rowCount() is calling for all top level items when I emit headerDataChanged() signal which leads to further delay in selecting item & changing header.
    Think how to avoid changing the header too often. You can always show a custom header instead of the default one.
    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: 10
    Last Post: 21st May 2015, 18:11
  2. Replies: 16
    Last Post: 12th May 2015, 21:46
  3. Replies: 1
    Last Post: 14th March 2013, 22:50
  4. QTreeWidget::findItems only searches top level items ?
    By krisha in forum Qt Programming
    Replies: 3
    Last Post: 27th October 2011, 08:28
  5. Replies: 4
    Last Post: 4th June 2007, 12:07

Tags for this Thread

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.