Results 1 to 11 of 11

Thread: problem withh QListViewItemIterator

  1. #1
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default problem withh QListViewItemIterator

    Hello ppl,

    I have got a probleem with QlistViewItemIterator, it doent not werk well by me.
    i want to search in my listview voor something. I just get the first item on my list en it seems dat the search mechanism doen not work well.

    this is my code:

    Qt Code:
    1. void test::selectItem( QString name, int type )
    2. {
    3. QString _cmp_name = name.section(":", 0, 0);
    4. QListViewItem* item;
    5. QString _x_name = name.section(":", 1, 1);
    6. QListViewItem * _cmp_item = (((CView *)(pWorkView->pStack->visibleWidget()))->ui_view->firstChild()->firstChild());
    7. QListViewItemIterator it2= _cmp_item;
    8. QListViewItem * _child_item = _cmp_item->firstChild();
    9. item = _child_item;
    10.  
    11. while (_child_item)
    12. if ( _child_item->text(0) == _x_name )
    13. {
    14. item = _child_item;
    15. break;
    16. }
    17. else
    18. {
    19. item = _child_item->nextSibling();
    20. }
    21.  
    22. while(*it2)
    23. {
    24. if(it2.current()->text( 0 ).contains(_x_name))
    25. {
    26. if ((*it2) && !(*it2)->pixmap(0))
    27. {
    28. ((CView *)(pWorkView->pStack->visibleWidget()))->selectItem(*it2);
    29. pWorkView->m_TabView->setCurrentPage(0);
    30. ((CView *)(pWorkView->pStack->visibleWidget()))->ui_view->ensureItemVisible(*it2);
    31. break;
    32. }
    33. }
    34. it2++;
    35. }
    36.  
    37. }
    To copy to clipboard, switch view to plain text mode 

    thanx in advance
    Love::Peace

  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: problem withh QListViewItemIterator

    The code seems quite complicated... can't you use QListView::findItem() instead? What is it exactly that you want to find?

  3. #3
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh QListViewItemIterator

    Quote Originally Posted by wysota View Post
    The code seems quite complicated... can't you use QListView::findItem() instead? What is it exactly that you want to find?

    I want to search the child items of my list. take a look at this picture:-



    in this list i want to search for example for the child item of C5, but i always get the first item en the first child in the list. i have tried it with findItem but when there is match(if the seach finds that there are two children with the same name, it will stop and i will get no results)it does not work.
    Love::Peace

  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: problem withh QListViewItemIterator

    Do you know up front that you'll be looking for a child of C5?

  5. #5
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh QListViewItemIterator

    Quote Originally Posted by wysota View Post
    Do you know up front that you'll be looking for a child of C5?
    sorry i did not get u ..
    Love::Peace

  6. #6
    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: problem withh QListViewItemIterator

    Do you know apriori (before starting the search) that the result you're looking for is a child of C5? Or is it just that you search all items and want to get an item which only happens to be a child of C5.

  7. #7
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh QListViewItemIterator

    Quote Originally Posted by wysota View Post
    Do you know apriori (before starting the search) that the result you're looking for is a child of C5? Or is it just that you search all items and want to get an item which only happens to be a child of C5.
    I will try to explain this problem as follow:

    Qt Code:
    1. QString _cmp_name = name.section(":", 0, 0);
    2. QString _x_name = name.section(":", 1, 1);
    To copy to clipboard, switch view to plain text mode 

    with the above code i get the name of C5 and the child of C5 which is 1..

    Qt Code:
    1. QListViewItem * _cmp_item = (((CView
    2.  
    3. *)(pWorkView->pStack->visibleWidget()))->ui_view->firstChild()->firstChild());
    To copy to clipboard, switch view to plain text mode 

    this is the pointer to the ListView in which all those item are available(see the picture)

    this is my listviewItem iterator, which would iterate in the listview..
    Qt Code:
    1. QListViewItemIterator it2= _cmp_item;
    To copy to clipboard, switch view to plain text mode 

    in this place i search if the child item which i select is equal to the _x_name
    if it is so i will get highlighted.(see the picture)
    if it is not so it should iterate on my list till it will find the childItem

    Qt Code:
    1. while (_child_item)
    2.  
    3. if ( _child_item->text(0) == _x_name )
    4.  
    5. {
    6.  
    7. item = _child_item;
    8.  
    9. break;
    10.  
    11. }
    12.  
    13. else
    14.  
    15. {
    16.  
    17. item = _child_item->nextSibling();
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 


    in this code i will search for the childItem, but u see i have a probleem that the most of the childItems have the same name for example "1" is the name of childItem of C5 en that of C1 and almost all of the items have the same childItem name and this code finds the childItem of first item in the list and do not see further. I select for example C5's child item which is "1", but this code hightlight the wrong childItem (the first occurance)
    Qt Code:
    1. while(*it2)
    2.  
    3. {
    4.  
    5. if(it2.current()->text( 0 ).contains(_x_name))
    6.  
    7. {
    8.  
    9. if ((*it2) && !(*it2)->pixmap(0))
    10.  
    11. {
    12.  
    13. ((CView *)(pWorkView->pStack->visibleWidget()))->selectItem(*it2);
    14.  
    15. pWorkView->m_TabView->setCurrentPage(0);
    16.  
    17. ((CView *)(pWorkView->pStack->visibleWidget()))->ui_view->ensureItemVisible(*it2);
    18.  
    19. break;
    20.  
    21. }
    22.  
    23. }
    24.  
    25. it2++;
    To copy to clipboard, switch view to plain text mode 
    Love::Peace

  8. #8
    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: problem withh QListViewItemIterator

    Ok, let's assume I know what you mean

    Qt Code:
    1. QListViewItem *MyClass::findItem(QListView *lv, QString parentName, QString childName){
    2. QListViewItem *pitem = lv->findItem(parentName, 0): // find parent item
    3. if(!pitem)
    4. return 0; // parent item not found
    5. // iterate child items:
    6. for(QListViewItem *iter = pitem->firstChild(); iter!=0; iter = iter->nextSibling()){
    7. if(iter->text(0) == childName) // texts match
    8. return iter; // return item
    9. }
    10. return 0; // child item not found
    11. }
    To copy to clipboard, switch view to plain text mode 

  9. #9
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh QListViewItemIterator

    Quote Originally Posted by wysota View Post
    Ok, let's assume I know what you mean

    Qt Code:
    1. QListViewItem *MyClass::findItem(QListView *lv, QString parentName, QString childName){
    2. QListViewItem *pitem = lv->findItem(parentName, 0): // find parent item
    3. if(!pitem)
    4. return 0; // parent item not found
    5. // iterate child items:
    6. for(QListViewItem *iter = pitem->firstChild(); iter!=0; iter = iter->nextSibling()){
    7. if(iter->text(0) == childName) // texts match
    8. return iter; // return item
    9. }
    10. return 0; // child item not found
    11. }
    To copy to clipboard, switch view to plain text mode 

    nope this methode i have tried earlier it doesnot work because if it finds a match the search stops and returns 0. FindItem() is not appropraite to use somehow. My last code works but it does not iterate well. I get the childItem but the first childItem in the list. In your methode i only find the childItems which occoured one time in de list.
    Love::Peace

  10. #10
    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: problem withh QListViewItemIterator

    How about this:
    Qt Code:
    1. QListViewItem *MyClass::findItem(QListView *lv, QString parentName, QString childName){
    2. QListViewItem *pitem;
    3. for(pitem = lv->firstChild(); pitem; pitem = pitem->nextSibling()){
    4. if(pitem->text(0) == parentName)
    5. break;
    6. }
    7. if(!pitem)
    8. return 0;
    9. for(QListViewItem *iter = pitem->firstChild(); iter!=0; iter = iter->nextSibling()){
    10. if(iter->text(0) == childName)
    11. return iter;
    12. }
    13. return 0;
    14. }
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to wysota for this useful post:

    :db:sStrong (7th March 2007)

  12. #11
    Join Date
    Feb 2006
    Posts
    51
    Thanks
    7

    Default Re: problem withh QListViewItemIterator

    Quote Originally Posted by wysota View Post
    How about this:
    Qt Code:
    1. QListViewItem *MyClass::findItem(QListView *lv, QString parentName, QString childName){
    2. QListViewItem *pitem;
    3. for(pitem = lv->firstChild(); pitem; pitem = pitem->nextSibling()){
    4. if(pitem->text(0) == parentName)
    5. break;
    6. }
    7. if(!pitem)
    8. return 0;
    9. for(QListViewItem *iter = pitem->firstChild(); iter!=0; iter = iter->nextSibling()){
    10. if(iter->text(0) == childName)
    11. return iter;
    12. }
    13. return 0;
    14. }
    To copy to clipboard, switch view to plain text mode 

    thnx alot it works just fine
    Love::Peace

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. problem withh returnPressed
    By :db:sStrong in forum Qt Programming
    Replies: 16
    Last Post: 23rd May 2006, 10:35
  3. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  4. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.