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. Crash of QListWidget when renaming item by program
Forum Updated to NodeBB v4.3 + New Features

Crash of QListWidget when renaming item by program

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 1.7k 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.
  • A Offline
    A Offline
    AngeSurTerre
    wrote on last edited by
    #1

    Hello,

    I have a QListWidget to which I add items with the following:
    @MyList->addItem(new QListWidgetItem("MyItemName");@

    Then when I run the code, I can click on the different items and my code takes the proper actions. No problem with that!

    The problem arises when, for some reasons that are too long (and useless) to explain I call a function that renames the selected item. This function contains the line:
    @MyList->currentItem()->setText("New name");@

    When this function is called, the item gets properly renamed. But if I select another item and reselect the item that I just renamed, then the code crashes with the error message:
    [quote]ASSERT failure in QVector<T>::operator[]: "index out of range", file /usr/include/qt5/QtCore/qvector.h, line 369[/quote]

    Anything I am doing wrong?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      msue
      wrote on last edited by
      #2

      Not with the two lines you posted. The problem has to do with the rest of your code.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        AngeSurTerre
        wrote on last edited by
        #3

        But if I comment the line
        @MyList->currentItem()->setText("New name");@

        then the code doesn't crash when I select another item and reselect the item that I want to change the name.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andreyc
          wrote on last edited by
          #4

          As msue said it is hard to tell what happens with only two lines of code.
          I guess that selected and current items are not the same.
          You can have a "list":http://qt-project.org/doc/qt-5/qlistwidget.html#selectedItems of selected items but a current item is only one.

          Try to check what is the result of MyList->currentItem() before trying to set a text.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            AngeSurTerre
            wrote on last edited by
            #5

            Thank you, I'll check that!

            1 Reply Last reply
            0

            • Login

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