[SailfishDevel] App own C++ plugin equivalent to Silica Theme

Thomas Perl th.perl at gmail.com
Tue Jan 28 20:27:50 UTC 2014


On 2014-01-28 10:59, christopher.lamb at thurweb.ch wrote:
> I would like to create a C++ plugin for my app to export common UX 
> settings as constants to the QML side (Things like font sizes, margin 
> sizes that reoccur throughout the app.)
>
> In essence I want something very similar to the functionality offered 
> by by the Silica Theme.
>
> After some experimentation I have hit on a solution that both compiles 
> and works. This is pasted at the bottom of this mail.
>
> I have 2 questions:
>
> 1) Is there a more elegant solution to achieve the same goal?

Not sure if it's more elegant, but back in the Harmattan days with 
gPodder, I just collected all constants in a "config.js" file and 
imported that in QML:

https://github.com/gpodder/gpodder/blob/master/share/gpodder/ui/qml/config.js

 From QML (assuming it's in the same folder), you can then do:

import "config.js" as Config

And if you have "var blubb = 123" in your config.js file, and you have 
imported it like above, you can then use "Config.blubb" to access that 
value.

> 2) From the C++ side, can I access the Silica them UX constants? e.g 
> to set some of my constants based on Silica constants? 

If you go with the JavaScript solution, you can import the Silica Theme 
class and use it in your JS, you can do this with something like:

http://qt-project.org/doc/qt-5.0/qtqml/qtqml-javascript-imports.html#importing-a-qml-module-from-a-javascript-resource


HTH :)
Thomas


More information about the Devel mailing list