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. QML ComboBox get selected item from C++ [SOLVED]
Forum Updated to NodeBB v4.3 + New Features

QML ComboBox get selected item from C++ [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 8.0k 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.
  • F Offline
    F Offline
    Folderol
    wrote on last edited by
    #1

    QT 5.1
    So my problem is that i cannot get the selected item from an Combobox via C++.
    The Combobox is created in QML.
    @
    ComboBox {
    id: comboBoxObjekt;
    objectName: "comboBoxObjekt";
    activeFocusOnPress: true;
    anchors.fill: parent;
    model: m_Objekt;
    }//ComboBoxObjekt
    @

    i can get my combobox like this.
    @
    item = this->View.rootObject()->findChild<QQuickItem*>( "comboBoxObjekt");
    @

    i can set items to my combobox like this.
    @
    this->current = this->View.rootContext();
    //some code
    this->current->setContextProperty("m_Objekt", QVariant::fromValue(dataList));
    @

    so when i try to get the selected item i use my
    @
    item = this->View.rootObject()->findChild<QQuickItem*>( "comboBoxObjekt");
    @

    to get the my combobox. then i connect my combobox like this

    @
    QObject::connect(CB,SIGNAL(currentIndexChanged()),this,SLOT(setupProject())); //Works

    QObject::connect(CB,SIGNAL(currentIndexChanged(int)),this,SLOT(setupProject(int))); //Error
    QObject::connect(CB,SIGNAL(currentIndexChanged(QString)),this,SLOT(setupProject(QString))); //Error
    @
    and i have read that you can use the signal currentIndexChanged(int) or (QString) to pass the current item as index = int or Text = QString? but because my CB is of QQuickItem i dont think thats possible? because when i try to use it i get these results.

    No such signal ComboBox_QMLTYPE_26::currentIndexChanged(QString).
    No such signal ComboBox_QMLTYPE_26::currentIndexChanged(int)

    but if i use the one that work i can use the connect but i cant access the selected item?
    So any idés of how i can access the current item from my combobox without creating a QCombobox in C++?

    If i have misunderstood anything please enlighten me. Thanks in advance

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Folderol
      wrote on last edited by
      #2

      [SOLVED]
      CB->property("currentText").toString();
      Got the current value from ComboBox with property currentText.

      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