Skip to content
QtWS25 Call for Papers
  • 0 Votes
    5 Posts
    738 Views
    fcarneyF

    If you use the the same model instance in more than one place they will always have the same index. This may, or may not be what you want. FYI

  • 0 Votes
    3 Posts
    2k Views
    P

    @raven-worx Thanks for your answer. There is no other place in the code where I update/modify the model. Also the combo box is already created when the slot is connected and called, if this is what you meant. Initially I declare the combo box as such with an empty model:

    ComboBox { id: comboInput visible: false anchors.fill: parent model: ListModel { id: model } }

    And this is the connection in C++ (plus the code to get the settings view inside which the combo box exists):

    //Connect signals emitted and received by Settings Form m_pQmlRoot = qmlEngine.rootObjects()[0]; item = qvariant_cast<QObject*>(m_pQmlRoot->property("settingsPage")); QObject::connect(bluetoothManager, SIGNAL(sig_DeviceDiscovered(QVariant)), item, SLOT(slot_deviceDiscovered(QVariant)));
  • 0 Votes
    5 Posts
    3k Views
    Fahad Al-SaidiF

    @Devopia53 Thanks, the checkboxes are displayed at least but selection by mouse is very difficult. I don't know why. UPDATE I comment out li->flags() and things works fine.

  • 0 Votes
    3 Posts
    11k Views
    M

    You need to change QStringList to QList<QObject*>
    From

    class ComboboxUpdate:public QObject { Q_OBJECT Q_PROPERTY(QStringList comboList READ comboList) ... }

    to

    class ComboboxUpdate:public QObject { Q_OBJECT Q_PROPERTY(QList<QObject*> comboList READ comboList) }

    for example you could change your code in this way or add a subclass

    class ComboboxUpdate:public QObject { Q_OBJECT Q_PROPERTY(QStringList comboList READ comboList) Q_PROPERTY(int sqlid READ sqlid WRITE setSqlid NOTIFY sqlidChanged) Q_PROPERTY(QString text READ text WRITE setText NOTIFY textChanged) }

    and in ComboBox you can use

    ComboBox { id: typeComboBox model:combomodel.comboList textRole: "text" onCurrentIndexChanged: { var sqlid = typeComboBox.model[typeComboBox.currentIndex].sqlid; console.log(sqlid); } }

    I hope that my answer will be helpful for you.

  • 0 Votes
    9 Posts
    3k Views
    SGaistS

    Thanks for sharing your findings !

    It indeeds make sense since the views are read-only

    Since you have a workaround, can you please update the thread title prepending [solved] so other forum users may know a solution has been found :)