このページでは

QQmlProperty Class

QQmlProperty クラスは、QML から生成されたオブジェクトのプロパティへのアクセスを抽象化します。詳細...

ヘッダー: #include <QQmlProperty>
CMake: find_package(Qt6 REQUIRED COMPONENTS Qml)
target_link_libraries(mytarget PRIVATE Qt6::Qml)
qmake: QT += qml
QML内では: qmlProperty

パブリック型

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 view(QUrl::fromLocalFile("MyItem.qml"));
QQmlProperty property(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::InvalidCategory0プロパティが無効であるか、シグナルプロパティです。
QQmlProperty::List1このプロパティは、QQmlListProperty のリストプロパティです。
QQmlProperty::Object2このプロパティは、QObject リストプロパティです
QQmlProperty::Normal3プロパティは通常の値プロパティです。

enum QQmlProperty::Type

この列挙型は、QMLプロパティの型を指定します。

定数値説明
QQmlProperty::Invalid0このプロパティは無効です。
QQmlProperty::Property1このプロパティは無効です。このプロパティは通常の Qt プロパティです。
QQmlProperty::SignalProperty2このプロパティはシグナルプロパティです。

プロパティのドキュメント

[read-only] name : const QString

このプロパティには、QMLプロパティの名前が格納されます。

アクセス関数:

QString name() const

関連項目: QQmlProperty::object 。

[read-only] object : QObject* const

このプロパティは、QMLプロパティによって表されるQObject を保持します。

アクセス関数:

QObject *object() const

「QQmlProperty::name」も参照してください 。

メンバ関数のドキュメント

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

プロパティ「category」を返します。

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)

other をこのQQmlProperty に割り当ててください。

bool QQmlProperty::operator==(const QQmlProperty &other) const

other とこのQQmlProperty が同じプロパティを表している場合、true を返します。

© 2026 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.