Clearing a QListWidget from private slot



  • Hi,

    I'm trying to clear the content of QListWidget using the following code:

    ui->displayChildLWidget->clear();
    

    as first line in a private slot and it's not working, before the code that adds items to the QListWidget. It simply adds to the content of QListWidget from the previous runs. For example, if Mike was displayed inside displayChildLWidget in first run, if run again to display Robert, it displays Mike followed by Robert instead of just Robert. If run again to display Joe, it dispalys

    Mike
    Mike
    Robert
    Mike
    Robert
    Joe

    The same code QListWidget->clear() works fine inside other functions. Does QListWidget inside private slot have to be handled differently?


  • Qt Champions 2016

    Hi
    are you sure the slot is called?
    insert qDebug() << "in slot" ;
    to be sure.



  • The slot role is to display info and part of it is the QListWidget. The info is displayed so I have no doubt that the slot is called. The issue is only in the QListWidget; it adds to the info from the previous search.

    If in the first Seach, I search for person A who has child "Mike", it displays Mike. If I search for person B who has child "Ryan", it displays Mike followed by Ryan instead of just Ryan


  • Qt Champions 2016

    @WhatIf said:

    Hmm, i cannot reproduce it.
    it clear the list even if slot is private

    https://www.dropbox.com/s/36yq306z31agvov/clearlist.zip?dl=0

    so I think you have some other bug :)



  • Found it :)

    The QListWidget was used somewhere else......my mistake.

    Thanks!


Log in to reply
 

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