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



  • 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



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.