I'm new to Qt and QML. I want to show my list using combobox with the QStringList model. But, it doesn't work at all. Below is the related source code.
ListModelResourceManager.hpp
class ListModelResourceManager : public QObject {
Q_OBJECT
Q_PROPERTY(QStringList model MEMBER m_model NOTIFY modelChanged)
QStringList m_model;
public:
ListModelResourceManager(const QString& ctx_id, const QQmlApplicationEngine& engine, QObject* parent = nullptr);
public slots:
void update();
signals:
void modelChanged();
};
main.cpp
...
ListModelResourceManager lmResourceManager("MODEL_ResourceManagerList", engine);
...
engine.load(QUrl(QStringLiteral("qrc:/viewmain.qml")));
viewmain.qml
ComboBox {
id: idResourceList
height: 30
visible: true
//model: ["First", "Second", "Third"] // IT WORKS well!!!
model : MODEL_ResourceManagerList.model
onFocusChanged: {
MODEL_ResourceManagerList.update();
}
delegate: ItemDelegate {
width: parent.width
text: modelData
font.weight: idResourceList.currentIndex === index ? Font.DemiBold : Font.Normal
font.pixelSize: 30
highlighted: idResourceList.highlightedIndex == index
}
when using commented model definition ( model: ["First", "Second", "Third"] ) it works well.
please let me know what's wrong in my code part. thanks