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. Class QListWidget, method clear() don't work
Qt 6.11 is out! See what's new in the release blog

Class QListWidget, method clear() don't work

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

    Hello.
    I have a problem clearing QListWidget.
    I read documentation for this class and I understood that it was nessesary to use slot clear().
    But when i called it. QListWidget is not clearing.
    Tell me, please, why it does not work?

    1 Reply Last reply
    0
    • X Offline
      X Offline
      xeroblast
      wrote on last edited by
      #2

      i encounter something like this before,

      could you check your QListWidget if there is any signal that is connected?
      like you put a connect() on your QListWidget.

      disconnect that first then use clear();

      1 Reply Last reply
      0
      • R Offline
        R Offline
        Ruu_Rinki
        wrote on last edited by
        #3

        I want just clear my QListWidget, and i don't use emit signals for this class.
        If you say me to use connect(), then tell me please, which i must used signal so it clear all item in QListWidget?

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          The following snippet works for me:

          @
          for(int i = 0; i < 10; ++i) {
          QListWidgetItem *lwi = new QListWidgetItem(QString("Item #%1").arg(i+1), ui->listWidget);
          }

          connect(ui->pushButton, SIGNAL(clicked()), ui->listWidget, SLOT(clear()));
          

          @

          One I click the button, the list widget is cleared.

          Can you show us some code, please?

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • R Offline
            R Offline
            Ruu_Rinki
            wrote on last edited by
            #5

            ohhh, sorry for the trouble.
            It's work, I did not understand that the items on my listwidget is read from the local database, so when I do clear(), they again returned.
            thanks, thanks, thanks

            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