C
Qul::Singleton Struct
template <typename T> struct Qul::Singletonこのクラスを継承することで、C++のクラスまたは構造体をQMLに対してシングルトンとして公開できます。詳細...
| Header: | #include <qul/singleton.h> |
| Since: | Qt Quick Ultralite 1.0 |
| Inherits: | Qul::Object and Qul::SingletonBase |
静的パブリックメンバー
| T & | instance() |
詳細な説明
qmlinterfacegenerator ツールは、シングルトンから派生したクラスに対して、pragma Singletonディレクティブを含む QML 型を生成します。
このクラスは、Curiously recurring template pattern (CRTP)を使用しており、テンプレートパラメータには派生型を指定する必要があります。
最小限の例:
struct MySingleton : public Qul::Singleton<MySingleton> { Property<int> someProperty; int someFunction(int param); };
C++ コードから Singleton を使用しない場合は、上記の例で問題ありません。そうでない場合は、もう少し完全に記述する必要があります:
struct MySingleton : Qul::Singleton<MySingleton> { // Create friendship for a base class to be able to access private constructor friend struct Qul::Singleton<MySingleton> Property<int> someProperty; int someFunction(int param); private: MySingleton() {} // Private constructor MySingleton(const MySingleton &); // Non copy-constructible MySingleton &operator=(const MySingleton &); // Non copyable };
これで、MySingleton をQML側からも
C++からも安全にxml-ph-0000@deepl.internalを使用できるようになります:
void someFunction() { MySingleton::instance().someProperty.setValue(42); }
「シングルトン」および「QML でのシングルトンの定義」も参照してください 。
特定のQtライセンスの下で利用可能です。
詳細はこちらをご覧ください。