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. use QAbstractListModel(c++) class in QML ComboBox
Forum Updated to NodeBB v4.3 + New Features

use QAbstractListModel(c++) class in QML ComboBox

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 1.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.
  • chawilaC Offline
    chawilaC Offline
    chawila
    wrote on last edited by
    #1

    i tried these :

    ComboBox {
         width: parent.width * 0.9
         height: 40
         model: cplusplusModel.modelList
    }
    

    and i got:

    Unable to assign cplusplusModel to QString
    
    1 Reply Last reply
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      What's the type of cplusplusModel.modelList ?
      Can you show the header ?

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Qt Champions 2022
        wrote on last edited by
        #3

        Not sure what is your model implementation.

        Here is the simple thing which works

        ComboBox {
            model: myModel
            textRole: "name"
        }
        
        QQmlApplicationEngine engine;
        engine.rootContext()->setContextProperty("myModel",&myModel);
        engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
        

        myModel is inherited from QAbstractListModel. name role is defined in the model.

        Can you share you model implementation ?

        Dheerendra
        @Community Service
        Certified Qt Specialist
        http://www.pthinks.com

        1 Reply Last reply
        2
        • chawilaC Offline
          chawilaC Offline
          chawila
          wrote on last edited by
          #4

          Thanks @dheerendra

          it worked!.
          i was omitting the textRole.

          My model type is :

          QList<QObject*>
          
          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