[SailfishDevel] Problem in interaction qml and c++

michael fuchs fooxl at posteo.at
Thu Apr 23 07:50:51 UTC 2020



Am 23.04.2020 08:59 schrieb David Llewellyn-Jones:
> On 23/04/2020 09:51, Michael Fuchs wrote:
>> How can AlbumList access mImgDB and mNetAccess?
>> 
>> One solution could be to register the controller itself in qml and 
>> then write
>> sth like this in qml:
>> 
>> ====
>> AlbumList {
>>   imgDB: controller.imgDB
>>   netAccess: controller.netAccess
>> }
>> ====
>> 
>> but it's redundant.
> 
> This doesn't look like a bad approach to me (although passing the
> controller itself might be cleaner).
> 
> An alternative might be to make Controller a singleton, that way your
> AlbumList class could access it from the C++ without needing to be
> explicitly passed a handle to it.
> 
> But whether you can do that depends on the how Controller is used.
> 

Thanks a lot.
I'm not familiar with singletons, but this sounds promising.
I found this simple example:

https://gist.github.com/pazdera/1098119

I hope this also works for Q_OBJECT s.
Maybe I should rather make netAccess and imgDB itself singletons?

fooxl




More information about the Devel mailing list