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

christopher.lamb at thurweb.ch christopher.lamb at thurweb.ch
Tue Jan 28 09:59:47 UTC 2014


Hi All

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?

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?

Grüsse

Chris

//start landedtheme.h
#ifndef LANDEDTHEME_H
#define LANDEDTHEME_H
#include <QObject>
class LandedTheme : public QObject
{
     Q_OBJECT
     Q_PROPERTY(int MarginSmall READ MarginSmall CONSTANT)
     //many more similar Q_PROPERTY declarations here
public:
     LandedTheme(QObject* parent = 0) : QObject(parent) {}
     int MarginSmall() const { return 10;}
     //many more similar variables here
};
#endif // LANDEDTHEME_H
//end landedtheme.h



//in the main .cpp file

#include "landedtheme.h"

static QObject *theme_singletontype_provider(QQmlEngine *engine,  
QJSEngine *scriptEngine)
{
     Q_UNUSED(engine)
     Q_UNUSED(scriptEngine)

     LandedTheme *landedTheme = new LandedTheme();
     return landedTheme;
}

//in the main function

qmlRegisterSingletonType<LandedTheme>("LandedTheme", 1, 0,  
"LandedTheme", theme_singletontype_provider);




More information about the Devel mailing list