Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Getting Combobox options from SQLite database / table
Forum Updated to NodeBB v4.3 + New Features

Getting Combobox options from SQLite database / table

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
2 Posts 2 Posters 295 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.
  • M Offline
    M Offline
    MaximBozek
    wrote on last edited by
    #1

    Hi, I am trying to put entries from my SQLite table into a combobox as the options. can't get it working, this is my current code:

                   ComboBox {
                       id: plate_empty
                       width: 400
                       height: 100
                       anchors.centerIn: parent
                       model: platesModel
                       textRole: "plate"  // Specifies which role contains the text to display
    
                       onCurrentIndexChanged: {
                           console.log("Selected plate:", plate_empty.currentText)
                       }
    
                       ListModel {
                           id: platesModel
                           Component.onCompleted: {
                               // Fetch plates from the backend and populate the model
                               TruckDatabase.get_all_plates().then(function(result) {
                                   platesModel.clear()
                                   for (var i = 0; i < result.length; i++) {
                                       platesModel.append({"plate": result[i]})
                                   }
                               }).catch(function(error) {
                                   console.log("Error fetching plates:", error)
                               })
                           }
                       }
                   }
    

    Anyone know a solution?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      Use QSqlQueryModel from C++/Python and pass that as a model to your combobox

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      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