Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Removing items from the QListWidget
QtWS25 Last Chance

Removing items from the QListWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 539 Views
  • 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.
  • B Offline
    B Offline
    BartoszT
    wrote on 19 Apr 2020, 16:41 last edited by
    #1

    I use a list from which items are removed one at a time. The current list item is deleted. Deleting the second to last one always fails with the at () function error: index out of range.
    Iterating through the list is ok, it reads and displays all the elements of the list correctly
    There is more details

    4d014fef-8874-4dcb-830b-c766149b2aaa-image.png

    how to fix it?

    B 1 Reply Last reply 19 Apr 2020, 16:53
    0
    • B BartoszT
      19 Apr 2020, 16:41

      I use a list from which items are removed one at a time. The current list item is deleted. Deleting the second to last one always fails with the at () function error: index out of range.
      Iterating through the list is ok, it reads and displays all the elements of the list correctly
      There is more details

      4d014fef-8874-4dcb-830b-c766149b2aaa-image.png

      how to fix it?

      B Offline
      B Offline
      Bonnie
      wrote on 19 Apr 2020, 16:53 last edited by
      #2

      @BartoszT
      How do you "Deleting the second to last one"?
      Also by deleting currentItem()?
      Deleting by iterating should be careful, the index and size are changing.

      1 Reply Last reply
      1
      • B Offline
        B Offline
        BartoszT
        wrote on 19 Apr 2020, 18:44 last edited by
        #3

        MY CODE works in signal button function

        void MainWindow::on_pushButtonDELETE_clicked()
        

        ListItem is deleted one by one for every button click
        Deleting is two lines of MY CODE as you see above

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 19 Apr 2020, 18:50 last edited by
          #4

          Hi,

          AFAIR, you should use takeItem before deleting it.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1

          3/4

          19 Apr 2020, 18:44

          • Login

          • Login or register to search.
          3 out of 4
          • First post
            3/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved