Results 1 to 4 of 4

Thread: 2 Questions about QListWidget

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up 2 Questions about QListWidget

    Hi all, in my application I use a QListWidget of icons, an I've got 2 questions about it:
    1) In some moments I need to do a processation of all the selected items in the list. What do you think that's the best way to do it: calling QListWidget::selectedItems and then process all the returned items or directly search for all the items in the list which is selected and process it. I have read the source code to see if "selectedItems" method saves internally a list with the current selected items (as I think) or simply it makes a search for all the items of the list to see which are selected. But I haven't found it. Anyone knows it?

    2) This question is related with previous. Do you think that QListWidget::findItems uses an eficient way to make the search (i.e a kind of dictionary or hash with the items of the list) or simply it searches for all the items in the list testing which of they matches with the text and the flags of the search?

    Thanks.
    Last edited by SkripT; 23rd March 2006 at 00:27.

  2. #2
    Join Date
    Mar 2006
    Location
    India
    Posts
    15
    Thanks
    5
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: 2 Questions about QListWidget

    Quote Originally Posted by SkripT
    I have read the source code to see if "selectedItems" method saves internally a list with the current selected items (as I think) or simply it makes a search for all the items of the list to see which are selected.
    Well, without looking at the source code I can say, it is better to use a method like 'selectedItems', because, it can always be optimised in the future.

    Basically, in OOP methodology, the details of the implementation should not be exposed to the clients. So, if a feature is being provided by an object, you can assume it has been implemented in the best possible way internally by that object.
    Qt 4.2 (qt-copy in KDE svn)
    KDE 4.0 (svn)
    Currently developing Anthias

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: 2 Questions about QListWidget

    Quote Originally Posted by ePharaoh
    Well, without looking at the source code I can say...
    Thanks ePharaoh for the suggestion, but I want to know it as exactly as possible because I could have a list of several items, and I don't want to go through it two times

  4. #4
    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: 2 Questions about QListWidget

    You could find answers to these kind of questions by looking at the source code by yourself..

    1) Item based views have a same kind of selection model than model based views. So it doesn't iterate through all items and check for selected ones. The selection model keeps track of selected items.

    2) See QAbstractItemModel::match(). It iterates through appropriate indexes.

  5. The following user says thank you to jpn for this useful post:

    SkripT (23rd March 2006)

Similar Threads

  1. Segmentation Faul using addItem (QListWidget)
    By gnusar in forum Qt Programming
    Replies: 3
    Last Post: 8th November 2008, 09:27
  2. how to sync a QTreeWidget and a QListWidget?
    By zl2k in forum Qt Programming
    Replies: 2
    Last Post: 5th September 2008, 20:55
  3. QListWidget Problem
    By pmabie in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2007, 06:52
  4. Memory management questions (im new to Qt)
    By scarvenger in forum Qt Programming
    Replies: 2
    Last Post: 6th May 2007, 07:41
  5. Replies: 13
    Last Post: 15th December 2006, 11:52

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.