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. How to remove current model from ComboBox?
Forum Updated to NodeBB v4.3 + New Features

How to remove current model from ComboBox?

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 2 Posters 555 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.
  • EngelardE Offline
    EngelardE Offline
    Engelard
    wrote on last edited by Engelard
    #1

    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).

    raven-worxR 1 Reply Last reply
    0
    • EngelardE Engelard

      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).

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      3

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved