tl;dr:How can I use a list of strings defined in ECL as a ListView model in QML in Qt 5.6?
===
So I'm really not familiar with Qt, but since it is the GUI toolkit for Sailfish phones I have to use it.
I'm trying to make a list of strings in ECL available as model to a ListView which has been defined in QML. I've been looking at examples, specifically this one: https://gitlab.com/eql/EQL5/-/blob/master/examples/M-modules/quick/item-mode... but I cannot use it directly because of some constraints in my environment and I also cannot wrap my head about how to solve it.
This is the ListView in QML:
SilicaListView { anchors.fill: parent //model: ListModel { id: listModel } model: 100
header: PageHeader { title: "Messages" }
delegate: BackgroundItem { id: delegate
Label { text: "Item " + index }
onClicked: console.log("Clicked " + index) }
...
And this is what I have in Lisp so far:
;;; Model ;;; ;;; https://gitlab.com/eql/EQL5/-/blob/master/examples/M-modules/quick/item-mode...
(defun set-my-model () (qlet ((data (qvariant-from-value *pushover-messages* "QStringList"))) (|setContextProperty| (|rootContext| qml:*quick-view*) "myModel" data)))
Taken straight from the example. However, I'm not sure what to do with the `qml:*quick-view*`
The problem is my constraints:
- I cannot start Qt from Lisp like in the example. There's a C++ initializer which start s up all the Sailfish OS stuff and EQL. So far I'm doing `Lisp.call`s from QML which works well enough. (Also see Renaud's template which I based all this on: https://redmine.casenave.fr/projects/eql5-sfos/repository/44/revisions/maste... )
- Sailfish OS only supports Qt 5.6
Thanks, Erik
On 2020-12-16 11:04, Erik Winkels wrote:
tl;dr:How can I use a list of strings defined in ECL as a ListView model in QML in Qt 5.6?
So hopefully I just need to call the EQL5 version of `qmlRegisterType` as is done here: https://github.com/sailfishos/cppqml-sample/blob/master/src/cppqml.cpp
But I cannot find any examples of it, nor do I see it available in EQL5.
On 12/16/20, Erik Winkels aerique@xs4all.nl wrote:
So hopefully I just need to call the EQL5 version of `qmlRegisterType` as is done here: https://github.com/sailfishos/cppqml-sample/blob/master/src/cppqml.cpp
But I cannot find any examples of it, nor do I see it available in EQL5.
This would only make sense if you define your data model in C++, which is probably not what you want. You should be able to do everything from Lisp.
I'm not familiar with sailfish, but I'm certainly interested! Hopefully I can get around to try the sdk (if it can be run on the desktop somehow).
Paul
Some progress, although I haven't tried updating the model from Lisp yet, but to make sure you guys don't dive into it. This works for the model defined in ECL and showing it in a QML ListView:
(defun set-my-model () (eql:qlet ((data (eql:qvariant-from-value *pushover-messages* "QStringList"))) (eql:|setContextProperty| (eql:|rootContext| (qml:qview)) "myModel" data)))
So I was falling into my common trap of running on too many assumptions.
I also called `set-my-model` before `(ini-quick-view (main-qml))` as used in Renaud's template.
The examples help! It's a pity my use-case doesn't fit them 1 on 1.
Regards, Erik
Updating works now as well, so I'm going to leave you guys alone for now.
I've uploaded what I have here: https://git.sr.ht/~aerique/pusfofefe so you can comment on how to improve my QML and EQL code if you like.
Thanks for your patience!
On 12/16/20, Erik Winkels aerique@xs4all.nl wrote:
However, I'm not sure what to do with the `qml:*quick-view*`
In the C++ template you cited there is this call:
eql_fun ("app/qml:ini-lib", Q_ARG (QQuickView*, view.data ()), Q_ARG (const char*, mainQml.toLocalFile ().toLatin1 ().constData ()), Q_ARG (const char*, resRoot.toLocalFile ().toLatin1 ().constData ()));
I guess you're using the above function, so you just need to store the first argument (the QQuickView*) in a Lisp parameter, and use it instead of qml:*quickview*.
Paul