<div dir="ltr">The sane way to have the Theme element exported is via qmlRegisterSingletonType() so I think that's what sailors are doing :)<div><br></div><div>About the import, they probably just registered the singleton type using the Sailfish.Silica import URI, so you don't have to import another module to be able to access the Theme element ;)</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-01-28  <span dir="ltr"><<a href="mailto:christopher.lamb@thurweb.ch" target="_blank">christopher.lamb@thurweb.ch</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Thomas<br>
<br>
I was hoping you would answer 8-)<br>
<br>
The .js route did occur to me, but I initially decided to make that "Plan B".<br>
<br>
As the list of UX constants will be used by most of the QML files in my project, a shared js script (i.e. defined as .pragma library) would seem to be the way to go. But I was put off by an earlier thread that implied that .pragma js scripts could not access QML elements.<br>

<br>
If that thread was correct, then I could not use a .pragma js script to access Sailfish Theme constants. This implies that if I want the UX list to be able to access Sailfish Theme, it cannot be shared. However, I guess that the true hit on memory use is in making such a library non-shared may not be so important, but I need to do some more reflecting on that.<br>

<br>
In the Qt Project link that your provided, there is a cryptic comment that I find interesting:<br>
<br>
"<br>
In particular, this may be useful in order to access functionality provided via a singleton type; see qmlRegisterSingletonType() for more information.<br>
"<br>
<br>
How is the Sailfish Theme registered?<br>
<br>
I am also intrigued by the fact that in the early SDK Alphas we had to import Sailfish.Silica.theme in every qml file using Theme properties, but now Theme has become globally available without any need for an explicit import. How is that achieved?<br>

<br>
Grüsse<br>
<br>
Chris<br>
<br>
<br>
<br>
Zitat von "Thomas Perl" <<a href="mailto:th.perl@gmail.com" target="_blank">th.perl@gmail.com</a>>:<div class="HOEnZb"><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 2014-01-28 10:59, <a href="mailto:christopher.lamb@thurweb.ch" target="_blank">christopher.lamb@thurweb.ch</a> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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.)<br>
<br>
In essence I want something very similar to the functionality offered by by the Silica Theme.<br>
<br>
After some experimentation I have hit on a solution that both compiles and works. This is pasted at the bottom of this mail.<br>
<br>
I have 2 questions:<br>
<br>
1) Is there a more elegant solution to achieve the same goal?<br>
</blockquote>
<br>
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:<br>
<br>
<a href="https://github.com/gpodder/gpodder/blob/master/share/gpodder/ui/qml/config.js" target="_blank">https://github.com/gpodder/<u></u>gpodder/blob/master/share/<u></u>gpodder/ui/qml/config.js</a><br>
<br>
>From QML (assuming it's in the same folder), you can then do:<br>
<br>
import "config.js" as Config<br>
<br>
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.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
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?<br>
</blockquote>
<br>
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:<br>
<br>
<a href="http://qt-project.org/doc/qt-5.0/qtqml/qtqml-javascript-imports.html#importing-a-qml-module-from-a-javascript-resource" target="_blank">http://qt-project.org/doc/qt-<u></u>5.0/qtqml/qtqml-javascript-<u></u>imports.html#importing-a-qml-<u></u>module-from-a-javascript-<u></u>resource</a><br>

<br>
<br>
HTH :)<br>
Thomas<br>
______________________________<u></u>_________________<br>
SailfishOS.org Devel mailing list<br>
<br>
</blockquote>
<br>
<br>
<br>
______________________________<u></u>_________________<br>
SailfishOS.org Devel mailing list<br>
</div></div></blockquote></div><br></div>