Class QListWidget, method clear() don't work

  • 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?

  • 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();

  • 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?

  • 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?

  • 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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.