Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QWidget iterator
Qt 6.12 LTS is out! See what's new in the release blog

QWidget iterator

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MScottM
    wrote on last edited by
    #1

    Hello,

    I'm working on my project to update code written in 2001. I'm having trouble with a function that uses a QListViewItemIterator:

    ////////////////////////////////////
    //// Write each channel to file  ///
    ////////////////////////////////////
    bool BookmarkData::WriteCycle()
    {
      BookmarkItem *bm;
      bookmark_t data;
      QListViewItemIterator it ( bmList );  //<- error: unknown type name "QListViewItemIterator"
    
      // iterate through all items in the list
      for( ; it.current(); ++it){
    
         bm = (BookmarkItem *)it.current();
    
         bm->getBookmark( &data );
         
         // add number of child in case of folder
         if(bm->isFolderBegin()){
            data.freq = bm->childCount();
         }
    
         WriteEntry( &data );
    
      }
    
      return true;
    }
    

    BookmarkItem was a QListViewItem and I changed to QListWidgetItem.
    bmList is a QListView*.

    I'm not quite sure how to accomplish the same functionality as the original code. I haven't used iterators and would appreciate some advice on how to get this working in modern Qt.

    jsulmJ 1 Reply Last reply
    0
    • M MScottM

      Hello,

      I'm working on my project to update code written in 2001. I'm having trouble with a function that uses a QListViewItemIterator:

      ////////////////////////////////////
      //// Write each channel to file  ///
      ////////////////////////////////////
      bool BookmarkData::WriteCycle()
      {
        BookmarkItem *bm;
        bookmark_t data;
        QListViewItemIterator it ( bmList );  //<- error: unknown type name "QListViewItemIterator"
      
        // iterate through all items in the list
        for( ; it.current(); ++it){
      
           bm = (BookmarkItem *)it.current();
      
           bm->getBookmark( &data );
           
           // add number of child in case of folder
           if(bm->isFolderBegin()){
              data.freq = bm->childCount();
           }
      
           WriteEntry( &data );
      
        }
      
        return true;
      }
      

      BookmarkItem was a QListViewItem and I changed to QListWidgetItem.
      bmList is a QListView*.

      I'm not quite sure how to accomplish the same functionality as the original code. I haven't used iterators and would appreciate some advice on how to get this working in modern Qt.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @MScottM You can iterate ovet items in QListWidget using https://doc.qt.io/qt-6/qlistwidget.html#itemAt-1

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      3
      • M Offline
        M Offline
        MScottM
        wrote on last edited by
        #3

        @jsulm Qt is telling me: 'No member named 'itemAt in QListWidgetItem' - what am I doing wrong?

        QListWidgetItem* it;
        

        then,

        it->itemAt(x) // No member...
        
        jsulmJ 1 Reply Last reply
        0
        • M MScottM

          @jsulm Qt is telling me: 'No member named 'itemAt in QListWidgetItem' - what am I doing wrong?

          QListWidgetItem* it;
          

          then,

          it->itemAt(x) // No member...
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by jsulm
          #4

          @MScottM Did you read the documentation I gave you? itemAt is a method in QListWidget class...
          Also, it takes two parameters.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          4
          • Chris KawaC Offline
            Chris KawaC Offline
            Chris Kawa
            Lifetime Qt Champion
            wrote on last edited by Chris Kawa
            #5

            QListWidgetItem is an item type of QListWidget. QListWidget is a convenience class that combines a view and a model

            Since bmList is a QListView you can't use QListWidgetItem with it. QListView is a view class. There is no way to get an item because there are no items in it. It operates only on an abstract model. You can call model() to get it. It is of type QAbstractItemModel. From it you can get rowCount(), then in a loop get index() for each row and for that index you can read data().

            1 Reply Last reply
            2

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt
            • Unsolved