QQmlProperty Class
QQmlProperty クラスは、QML から生成されたオブジェクトのプロパティへの アクセスを抽象化したものです。さらに...
ヘッダ | #include <QQmlProperty> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Qml) target_link_libraries(mytarget PRIVATE Qt6::Qml) |
qmake: | QT += qml |
パブリックタイプ
enum | PropertyTypeCategory { InvalidCategory, List, Object, Normal } |
enum | Type { Invalid, Property, SignalProperty } |
パブリック関数
QQmlProperty() | |
QQmlProperty(QObject *obj) | |
QQmlProperty(QObject *obj, QQmlContext *ctxt) | |
QQmlProperty(QObject *obj, QQmlEngine *engine) | |
QQmlProperty(QObject *obj, const QString &name) | |
QQmlProperty(QObject *obj, const QString &name, QQmlContext *ctxt) | |
QQmlProperty(QObject *obj, const QString &name, QQmlEngine *engine) | |
QQmlProperty(const QQmlProperty &other) | |
bool | connectNotifySignal(QObject *dest, const char *slot) const |
bool | connectNotifySignal(QObject *dest, int method) const |
bool | hasNotifySignal() const |
int | index() const |
bool | isDesignable() const |
bool | isProperty() const |
bool | isResettable() const |
bool | isSignalProperty() const |
bool | isValid() const |
bool | isWritable() const |
QMetaMethod | method() const |
QString | name() const |
bool | needsNotifySignal() const |
QObject * | object() const |
QMetaProperty | property() const |
QMetaType | propertyMetaType() const |
int | propertyType() const |
QQmlProperty::PropertyTypeCategory | propertyTypeCategory() const |
const char * | propertyTypeName() const |
QVariant | read() const |
bool | reset() const |
QQmlProperty::Type | type() const |
bool | write(const QVariant &value) const |
QQmlProperty & | operator=(const QQmlProperty &other) |
bool | operator==(const QQmlProperty &other) const |
静的パブリックメンバ
QVariant | read(const QObject *object, const QString &name) |
QVariant | read(const QObject *object, const QString &name, QQmlContext *ctxt) |
QVariant | read(const QObject *object, const QString &name, QQmlEngine *engine) |
bool | write(QObject *object, const QString &name, const QVariant &value) |
bool | write(QObject *object, const QString &name, const QVariant &value, QQmlContext *ctxt) |
bool | write(QObject *object, const QString &name, const QVariant &value, QQmlEngine *engine) |
詳細説明
QML は Qt のメタ型システムを利用しているため、既存のQMetaObject クラスはすべて QML によって生成されたオブジェクトのイントロスペクトや相互作用に利用することができます。しかし、QMLが提供する新しい機能、例えば型安全性やアタッチドプロパティは、QQmlPropertyクラスを通して最も簡単に使用することができます。
QMetaProperty 、クラス型のプロパティを表すのとは異なり、QQmlProperty は特定のオブジェクトインスタンスのプロパティをカプセル化します。プロパティの値を読み取るには、プログラマーはQQmlPropertyインスタンスを作成し、read ()メソッドを呼び出します。同様に、プロパティの値を書き込むには、write ()メソッドを使用します。
例えば、次のようなQMLコードです:
// MyItem.qml import QtQuick 2.0 Text { text: "A bit of text" }
Text オブジェクトのプロパティには、QQmlProperty を使って次のようにアクセスできます:
#include <QQmlProperty>#include <QGraphicsObject>...QQuickViewビュー(QUrl::fromLocalFile("MyItem.qml"));QQmlPropertyproperty(view.rootObject(), "font.pixelSize");qWarning() << "Current pixel size:" << property.read().toInt(); property.write(24);qWarning() << "Pixel size should now be 24:" << property.read().toInt();
メンバー・タイプ・ドキュメンテーション
enum QQmlProperty::PropertyTypeCategory
この列挙型は QML プロパティのカテゴリを指定します。
定数 | 値 | 説明 |
---|---|---|
QQmlProperty::InvalidCategory | 0 | プロパティが無効であるか、シグナルプロパティである。 |
QQmlProperty::List | 1 | プロパティはQQmlListProperty リストプロパティです。 |
QQmlProperty::Object | 2 | プロパティはQObject 派生型ポインタです。 |
QQmlProperty::Normal | 3 | プロパティは通常値プロパティです。 |
enum QQmlProperty::Type
この列挙型は QML プロパティのタイプを指定します。
定数 | 値 | 説明 |
---|---|---|
QQmlProperty::Invalid | 0 | プロパティは無効です。 |
QQmlProperty::Property | 1 | プロパティは通常の Qt プロパティです。 |
QQmlProperty::SignalProperty | 2 | プロパティはシグナルプロパティです。 |
メンバ関数のドキュメント
QQmlProperty::QQmlProperty()
無効な QQmlProperty を作成します。
QQmlProperty::QQmlProperty(QObject *obj)
obj のデフォルト・プロパティの QQmlProperty を作成します。 デフォルト・プロパティがない場合は、無効な QQmlProperty が作成されます。
QQmlProperty::QQmlProperty(QObject *obj, QQmlContext *ctxt)
context ctxt を使用して、obj のデフォルトプロパティ用の QQmlProperty を作成します。デフォルト・プロパティがない場合は、無効な QQmlProperty が作成されます。
QQmlProperty::QQmlProperty(QObject *obj, QQmlEngine *engine)
engine が提供する QML コンポーネントのインスタンス化環境を使用して、obj のデフォルトプロパティの QQmlProperty を作成します。デフォルトプロパティがない場合は、無効なQQmlPropertyが作成されます。
QQmlProperty::QQmlProperty(QObject *obj, const QString &name)
obj のプロパティname の QQmlProperty を作成します。
QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlContext *ctxt)
context ctxt を使用して、obj のプロパティname に対して QQmlProperty を作成します。
コンテキストなしでQQmlPropertyを作成すると、いくつかのプロパティ(添付プロパティなど)はアクセスできなくなります。
QQmlProperty::QQmlProperty(QObject *obj, const QString &name, QQmlEngine *engine)
engine が提供する QML コンポーネントのインスタンス化環境を用いて、obj のプロパティname の QQmlProperty を作成します。
QQmlProperty::QQmlProperty(const QQmlProperty &other)
other のコピーを作成する。
bool QQmlProperty::connectNotifySignal(QObject *dest, const char *slot) const
プロパティの変更通知シグナルをdest オブジェクトの指定されたslot に接続し、true を返します。このメタプロパティが通常の Qt プロパティを表していない場合、または変更通知シグナルを持たない場合、またはdest オブジェクトが指定されたslot を持たない場合は false を返します。
注意: slot は、正しく識別されるように、SLOT() マクロを使用して渡す必要があります。
bool QQmlProperty::connectNotifySignal(QObject *dest, int method) const
プロパティの変更通知シグナルをdest オブジェクトの指定されたmethod に接続し、true を返します。このメタプロパティが通常の Qt プロパティを表していない場合、または変更通知シグナルを持たない場合、またはdest オブジェクトが指定されたmethod を持たない場合は、false を返します。
bool QQmlProperty::hasNotifySignal() const
プロパティに変更通知シグナルがある場合はtrueを返し、そうでない場合はfalseを返します。
int QQmlProperty::index() const
プロパティの Qt メタオブジェクトインデックスを返します。
bool QQmlProperty::isDesignable() const
プロパティが設計可能であればtrueを返し、そうでなければfalseを返します。
bool QQmlProperty::isProperty() const
このQQmlProperty が通常の Qt プロパティを表す場合、true を返します。
bool QQmlProperty::isResettable() const
プロパティがリセット可能であればtrueを返し、そうでなければfalseを返します。
bool QQmlProperty::isSignalProperty() const
このQQmlProperty が QML シグナルプロパティを表す場合、true を返します。
bool QQmlProperty::isValid() const
QQmlProperty が有効なプロパティを参照している場合は true を返し、そうでない場合は false を返します。
bool QQmlProperty::isWritable() const
プロパティが書き込み可能であればtrueを返し、そうでなければfalseを返します。
QMetaMethod QQmlProperty::method() const
このプロパティがSignalProperty であればQMetaMethod を返し、そうでなければ無効なQMetaMethod を返す。
QString QQmlProperty::name() const
この QML プロパティの名前を返します。
注意: プロパティ名のゲッター関数です。
bool QQmlProperty::needsNotifySignal() const
プロパティがバインディングを最新に保つために変更通知シグナルが必要な場合はtrueを返し、そうでない場合はfalseを返します。
アタッチドプロパティや値が変更されないプロパティなど、一部のプロパティは変更通知シグナルを必要としません。
QObject *QQmlProperty::object() const
QQmlProperty のQObject を返します。
注: プロパティ・オブジェクトのゲッター関数。
QMetaProperty QQmlProperty::property() const
この QML プロパティに関連付けられたQt property を返します。
QMetaType QQmlProperty::propertyMetaType() const
プロパティのメタタイプを返します。
propertyTypeも参照してください 。
int QQmlProperty::propertyType() const
プ ロパテ ィ の メ タ タ イ プ ID を、 ま たはプ ロパテ ィ に メ タ タ イ プがない と きはQMetaType::UnknownType を返 し ます。
propertyMetaTypeも参照してください 。
QQmlProperty::PropertyTypeCategory QQmlProperty::propertyTypeCategory() const
プロパティのカテゴリを返します。
const char *QQmlProperty::propertyTypeName() const
プロパティの型名を返します。プロパティに型名がない場合は 0 を返します。
QVariant QQmlProperty::read() const
プロパティ値を返します。
[static]
QVariant QQmlProperty::read(const QObject *object, const QString &name)
このメソッドはobject のname プロパティ値を返す:
QQmlProperty p(object, name); p.read();
[static]
QVariant QQmlProperty::read(const QObject *object, const QString &name, QQmlContext *ctxt)
context ctxt を使用してobject のname プロパティ値を返す。このメソッドは以下と等価である:
QQmlProperty p(object, name, context); p.read();
[static]
QVariant QQmlProperty::read(const QObject *object, const QString &name, QQmlEngine *engine)
engine が提供する QML コンポーネントのインスタンス化環境を用いて、object のname プロパティ値を返す。このメソッドは
QQmlProperty p(object, name, engine); p.read();
bool QQmlProperty::reset() const
プロパティをリセットし、プロパティがリセット可能な場合は true を返す。プロパティがリセット可能でない場合は何も起こらず、false が返されます。
QQmlProperty::Type QQmlProperty::type() const
プロパティの型を返します。
bool QQmlProperty::write(const QVariant &value) const
プロパティ値をvalue に設定する。成功すればtrue
を返し、value の型が間違っているなどの理由でプロパティを設定できない場合はfalse
を返す。
[static]
bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &value)
object のname プロパティにvalue を書き込む。 このメソッドは以下と等価である:
QQmlProperty p(object, name); p.write(value);
成功した場合はtrue
を、そうでない場合はfalse
を返す。
[static]
bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &value, QQmlContext *ctxt)
context ctxt を使ってobject のname プロパティにvalue を書き込む。このメソッドは以下と等価である:
QQmlProperty p(object, name, ctxt); p.write(value);
成功した場合はtrue
を、そうでない場合はfalse
を返す。
[static]
bool QQmlProperty::write(QObject *object, const QString &name, const QVariant &value, QQmlEngine *engine)
engine が提供する QML コンポーネントのインスタンス化環境を用いて、object のname プロパティにvalue を書き込む。このメソッドは以下と等価です:
QQmlProperty p(object, name, engine); p.write(value);
成功すればtrue
を、そうでなければfalse
を返します。
QQmlProperty &QQmlProperty::operator=(const QQmlProperty &other)
QQmlProperty にother を割り当てる。
bool QQmlProperty::operator==(const QQmlProperty &other) const
other とこのQQmlProperty が同じプロパティを表す場合、true を返す。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.