<p style="margin:0;">Your needs are very similar to mine in kontroller app( this is to be expected, needs are very similar).</p><p style="margin:0;"> </p><p style="margin:0;">At first glance, i tried an approach using singleton objects, and qml objects were internally just proxy over the c++ singletons. This proved to be a total mess, not reliable (including several crashes due to c++ objects not correctly exposed to qml) so i strongly recommend not going this way.</p><p style="margin:0;"> </p><p style="margin:0;">What does work, and is much more clean from a design point of view, is exposing a « client » object (that would be your Controller if i understand correctly) as a context property of the root page. This is what you proposed :</p><p style="margin:0;">====<br>AlbumList {<br>imgDB: controller.imgDB<br>netAccess: controller.netAccess<br>}<br>====</p><p style="margin:0;"> </p><p style="margin:0;">There is no way to make qml call a specific constructor when creating an object (Qt 5.14 introduced required properties, so it may change in the future, but i wouln't count on it in the near future. Maybe for Qt6). However, the setProperty / refresh() in component.onCompleted event pattern works pretty well. It may be considered a bit redundant, but if/when you implement multiple servers and server switching, you'll be glad you went that way.</p><p style="margin:0;"> </p><p style="margin:0;">On a different topic, i would make two additional remarks based on my experience:</p><p style="margin:0;">* i would't use AlbumList as the model for the list. More precisely, i would use an AlbumService, which expose an albumList as a property (this is what i do in Kontroller). I found that exposing a QVariantList of Q_GADGETS gives pretty good result regarding performance (when qt gets upgraded, we will be able to expose directly a QVector<Album>, but not yet), ie even with more than 10k elements in list it works fine on a jolla 1.</p><p style="margin:0;">* i'm not sure what your ImageDatabase is, but did you look at QQuickImageProvider ? (https://doc.qt.io/archives/qt-5.6/qquickimageprovider.html ). It could be a better alternative (as it benefits a lot from internal qt caching / optimizations).</p><p style="margin:0;"> </p><p style="margin:0;">Best regards,</p><p style="margin:0;"> </p><p style="margin:0;">Julien</p><p style="margin:0;"> </p><p style="margin:0;">"Michael Fuchs" michfu@gmx.at – 23 avril 2020 08:51<br> </p><blockquote>Hi,<br><br>...I don't even know how to phrase the subject of this mail...<br><br>I'm hacking on SMPC and I want to reorganize the spaghettis of the code and<br>I'm stuck at a problem now, where I don't even know what to search for:<br><br>I created a c++ class called AlbumList, and i registered it in qml, ...<br><br>====<br>qmlRegisterType<AlbumList>("smpc", 1, 0, "AlbumList");<br>====<br><br>...so it can be instanciated there like this:<br>====<br>ListModel {<br>model: AlbumList { }<br>}<br>====<br><br>This works fine. Now that the object is instantiated it needs to fetch<br>information from mpd about the albums and get the coverimages from a database.<br>Both are instantiated in the "controller".<br><br>====<br>Controller::Controller(....) {<br>mImgDB = new ImageDatabase();<br>mNetAccess = new NetworkAccess();<br>}<br>====<br><br>The controller gets created in main.cpp:<br><br>====<br>Controller *control = new Controller(view,0);<br>====<br><br>How can AlbumList access mImgDB and mNetAccess?<br><br>One solution could be to register the controller itself in qml and then write<br>sth like this in qml:<br><br>====<br>AlbumList {<br>imgDB: controller.imgDB<br>netAccess: controller.netAccess<br>}<br>====<br><br>but it's redundant.<br>Isn't there a way I can solve this inside c++?<br>Do I have to register AlbumList differently in qml? Can I influence, which<br>constructor of AlbumModel is used by qml, so I can hand over netAccess and<br>imgDB as parameters.<br><br>I hope I could make myself clear about this.<br><br>Greetings, fooxl.<br><br><br><br>_______________________________________________<br><a href="http://SailfishOS.org">SailfishOS.org</a> Devel mailing list<br>To unsubscribe, please send a mail to <a href="mailto:devel-unsubscribe@lists.sailfishos.org">devel-unsubscribe@lists.sailfishos.org</a><br><br> </blockquote>