How to remove current model from ComboBox?

  • Hi. In some moment my app is needed to "clear" certain ComboBox from model i set previously. I can't rly find how to do this.

    In google some said use nullptr, it was first thought that i got myself, but every object(i assume) must have valid model.


    Which outputs in runtime this:

    QComboBox::setModel: cannot set a 0 model

    Second thing i found, is to set to empty model, which seems more logical.


    But unfortunately there is no such property in such class(at least i don't have it).

  • Moderators

    yes simply hold an empty model (like new QStringListModel). The few bytes of "wasted" memory is negligible.
    If you have multiple views/comboboxes you can use the same dummy model for all of them.

Log in to reply