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.
ui->comboBox_1T->setModel(nullptr);
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.
QAbstractItemModelPrivate::staticEmptyModel();
But unfortunately there is no such property in such class(at least i don't have it).
-
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.
ui->comboBox_1T->setModel(nullptr);
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.
QAbstractItemModelPrivate::staticEmptyModel();
But unfortunately there is no such property in such class(at least i don't have it).
@Engelard
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.