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. QCombobox with key and value

QCombobox with key and value

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qcomboboxkey and valuemodelqmlqt quick
4 Posts 2 Posters 2.4k 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.
  • T Offline
    T Offline
    tamlong0205
    wrote on last edited by tamlong0205
    #1

    I using QComboBox design in .qml file and get model from .cpp file.
    But I just can set model for ComboBox with QStringList (It work fine). But I want to set model with key and value for ComboBox. Any solution, please give me an advise.

    ComboBox {
                id: cboModel
                Layout.fillWidth: true
                model: myModel
    }
    

    My main.cpp

    QStringList myModel; 
    // Set data for myModel here.
    // set to rootContext
    QQmlApplicationEngine engine;
    engine.rootContext()->setContextProperty("myModel",QVariant::fromValue(myModel));
    
    raven-worxR 1 Reply Last reply
    0
    • T tamlong0205

      I using QComboBox design in .qml file and get model from .cpp file.
      But I just can set model for ComboBox with QStringList (It work fine). But I want to set model with key and value for ComboBox. Any solution, please give me an advise.

      ComboBox {
                  id: cboModel
                  Layout.fillWidth: true
                  model: myModel
      }
      

      My main.cpp

      QStringList myModel; 
      // Set data for myModel here.
      // set to rootContext
      QQmlApplicationEngine engine;
      engine.rootContext()->setContextProperty("myModel",QVariant::fromValue(myModel));
      
      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      @tamlong0205
      have you read this already?

      --- 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
      1
      • T Offline
        T Offline
        tamlong0205
        wrote on last edited by tamlong0205
        #3

        @raven-worx . I will try asap and reply here. Thank you very much.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          tamlong0205
          wrote on last edited by tamlong0205
          #4

          I had create a model with key and value and pass it to qml, it worked!!!
          Sorry for late reply.
          Thank you @raven-worx

          1 Reply Last reply
          0

          • Login

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