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. fill combobox with query results, but also <select>
QtWS25 Last Chance

fill combobox with query results, but also <select>

Scheduled Pinned Locked Moved Unsolved General and Desktop
qsqlquerymodelqcombobox
2 Posts 2 Posters 574 Views
  • 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.
  • H Offline
    H Offline
    hobbyProgrammer
    wrote on last edited by hobbyProgrammer
    #1

    Hi,

    I would like to fill a combobox using a QSqlQueryModel, which works fine btw.
    But I noticed that the default index is the result of the query with the lowest index.
    I'd like to be able to not fill in anything so is it possible to fill a combobox with <select> and then add the model?

    Like this:
    c102ed1c-af72-4cb5-b887-cb59fd2e78dc-image.png

    JonBJ 1 Reply Last reply
    0
    • H hobbyProgrammer

      Hi,

      I would like to fill a combobox using a QSqlQueryModel, which works fine btw.
      But I noticed that the default index is the result of the query with the lowest index.
      I'd like to be able to not fill in anything so is it possible to fill a combobox with <select> and then add the model?

      Like this:
      c102ed1c-af72-4cb5-b887-cb59fd2e78dc-image.png

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @hobbyProgrammer
      You cannot have a combo which is both bound to a model and has some extra row inserted into it --- it's one or the other.

      There are several possible approaches:

      • Make your SQL query return a UNION ALL which includes a literal <select> as an extra row. Not really nice, because it makes the <select> be an extra row from the query.

      • Copy the result set from the query into another model (you probably only need a list, perhaps a QStringList) where you insert the extra <select> as an item and use that as the combo's model. If you don't get a better example, this is the most obvious to code.

      • Interpose a QIdentityProxyModel between the query model and the combo, and add the extra row there. I suspect this is the way it's supposed to be done(?).

      1 Reply Last reply
      1

      • Login

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