2015. 8. 11. 23:41

The Property System 소개

The Property System

프로퍼티 (속성 값) 시스템

출처 : http://doc.qt.io/qt-5/properties.html

Qt provides a sophisticated property system similar to the ones supplied by some compiler vendors. However, as a compiler- and platform-independent library, Qt does not rely on non-standard compiler features like __property or [property]. The Qt solution works with any standard C++ compiler on every platform Qt supports. It is based on the Meta-Object System that also provides inter-object communication via signals and slots.

Qt 는 몇몇 컴파일러 업체 (벤더) 들이 제공하는 것과 유사한 정교한 프로퍼티 시스템을 제공합니다. 하지만, 컴파일러와 플랫폼에 독립적인 라이브러로서, Qt 는 __property 나 [property] 와 같은 비-표준 컴파일러 기능에 의존하지 않습니다. Qt 는 Qt 를 지원하는 플랫폼일면 어떤 표준 C++ 컴파일러에서도 동작됩니다. 이는 시그널과 슬롯을 통한 객체-간 (인터-오프젝트) 통신을 제공도 하는 메타-오브젝트 시스템에 기반 합니다.

Requirements for Declaring Properties

프로퍼티 값을 선언하기 위한 요구 사항

To declare a property, use the Q_PROPERTY() macro in a class that inherits QObject.

프로퍼티 값을 선언하기 위해, QObject 를 상속 받는 클래스 안에 Q_PROPERTY() 매크로를 사용합니다.

Q_PROPERTY(type name
           (READ getFunction [WRITE setFunction] |
            MEMBER memberName [(READ getFunction | WRITE setFunction)])
           [RESET resetFunction]
           [NOTIFY notifySignal]
           [REVISION int]
           [DESIGNABLE bool]
           [SCRIPTABLE bool]
           [STORED bool]
           [USER bool]
           [CONSTANT]
           [FINAL])

Here are some typical examples of property declarations taken from class QWidget.

QWidget 에서 가져온 전형적인 프로퍼티 선언의 예입니다.

Q_PROPERTY(bool focus READ hasFocus)
Q_PROPERTY(bool enabled READ isEnabled WRITE setEnabled)
Q_PROPERTY(QCursor cursor READ cursor WRITE setCursor RESET unsetCursor)

Here is an example showing how to export member variables as Qt properties using the MEMBER keyword. Note that a NOTIFY signal must be specified to allow QML property bindings.

여기는 MEMBER 키워드를 사용해 Qt 프로퍼티 값들을 구성원 (맴버) 변수로 내보내는 방법에 대한 예입니다. NOTIFY 시그널(신호) 는 QML 프로퍼티 바인딩을 할수 있게 구성되어 있어야 함을 참고 하시기 바랍니다.

    Q_PROPERTY(QColor color MEMBER m_color NOTIFY colorChanged)
    Q_PROPERTY(qreal spacing MEMBER m_spacing NOTIFY spacingChanged)
    Q_PROPERTY(QString text MEMBER m_text NOTIFY textChanged)
    ...
signals:
    void colorChanged();
    void spacingChanged();
    void textChanged(const QString &newText);

private:
    QColor  m_color;
    qreal   m_spacing;
    QString m_text;

A property behaves like a class data member, but it has additional features accessible through the Meta-Object System.

프로퍼티는 클래스 자료 구성원과 비슷하게 동작하지만, 메타-오브젝트 시스템을 통해 추가적인 기능을 가지고 있습니다.

  • READ accessor function is required if no MEMBER variable was specified. It is for reading the property value. Ideally, a const function is used for this purpose, and it must return either the property's type or a const reference to that type. e.g., QWidget::focus is a read-only property with READ function, QWidget::hasFocus().
  • READ 접근자 함수는 MEMBER 로 지정된 변수가 명시되어 있지 않다면, 필요로 합니다. 이는 프로퍼티 값을 읽는 용도입니다. 이상적으로 상수 함수 (함수내에서 값 변경을 하지 않음) 가 적절하고, 반드시 프로퍼티의 자료 형이나 해당 자료형을 가리키는 상수 참조자를 반환 해야합니다. 예. QWidget::focus 는 READ 함수인 QWidget::hasFocus() 를 사용하는 읽기-전용 프로퍼티 입니다.
  • WRITE accessor function is optional. It is for setting the property value. It must return void and must take exactly one argument, either of the property's type or a pointer or reference to that type. e.g.,QWidget::enabled has the WRITE function QWidget::setEnabled(). Read-only properties do not need WRITE functions. e.g., QWidget::focus has no WRITE function.
  • WRITE 접근자 함수는 선택사항입니다. 이것은 프로퍼티 값을 설정하는 용도 입니다. 반드시 void 형으로 반환하며, 정확히 하나의 인수를 받아야 하며, 프로퍼티의 자료형이거나 해당 자료형을 가리키는 포인터나 참조자야 합니다. 예. QWidget::enabled (프로퍼티) 는 WRITE 함수인 QWidget::setEnable() 을 가지고 있습니다. 읽기-전용 프로퍼티들은 WRITE 를 가질 필요가 없습니다. 예. QWidget::focus 는 WRITE 함수를 가지고 있지 않습니다.
  • MEMBER variable association is required if no READ accessor function is specified. This makes the given member variable readable and writable without the need of creating READ and WRITE accessor functions. It's still possible to use READ or WRITE accessor functions in addition to MEMBER variable association (but not both), if you need to control the variable access.
  • READ 연산자가 명시되어 있지 않다면 MEMBER 변수 연결이 필요합니다. 이는 READ 와 WRITE 접근자 함수를 만들 필요 없이 읽고 쓸수 있는 맴버 변수를 만들게 됩니다. 여전히 MEMBER 변수 연결을 하고도 변수 접근을 제어할 필요가 있다면 READ 또는 WRITE 접근자 함수 (모두는 아님) 를 만들 수 있습니다.
  • RESET function is optional. It is for setting the property back to its context specific default value. e.g.,QWidget::cursor has the typical READ and WRITE functions, QWidget::cursor() and QWidget::setCursor(), and it also has a RESET function, QWidget::unsetCursor(), since no call to QWidget::setCursor() can mean reset to the context specific cursor. The RESET function must return void and take no parameters.
  • RESET 함수는 선택사항입니다. 프로퍼티 값을 그(프로퍼티) 문맥상 지정된 기본값으로 되돌리게 해줍니다. 예. QWidget::cursor 는 일반적인 READ 와 WRITE 함수들이 있습니다, QWidget::cursor() 와 QWidget::setCursor() 가 있으며, 또한 아무도 QWidget::setCursor() 를 부르지 않는다는 것은 문맥상 지정된 커서로 설정을 다시 돌린다는 의미가 될 수 있기 때문에, RESET 함수인 QWidget::unsetCursor() 이 있습니다.
  • NOTIFY signal is optional. If defined, it should specify one existing signal in that class that is emitted whenever the value of the property changes. NOTIFY signals for MEMBER variables must take zero or one parameter, which must be of the same type as the property. The parameter will take the new value of the property. The NOTIFY signal should only be emitted when the property has really been changed, to avoid bindings being unnecessarily re-evaluated in QML, for example. Qt emits automatically that signal when needed for MEMBER properties that do not have an explicit setter.
  • NOTIFY 시그널은 선택사항입니다. 만약 정해진다면, 프로퍼티 값이 변경될 대 마다 발산되는 시그널을 포함하는 현존 클래스를 지정해야합니다. NOTIFY 시그널용 MEMBER 변수들은 파라미터를 가지지 않거나, 프로퍼티와 동일한 자료형인 한 개를 가져야 합니다. 그 파라미터는 프로퍼티의 새 값을 가지게 될 것입니다. NOTIFY 시그널은 예를 들어 QML 에서 값을 불필요하게 재계산 하는 것과 같은 바인딩을 피하기 위해 정말로 변경 되었을 때에만 발산되어야 합니다. 명시적인 셋터 (값 지정) 함수를 가지지 않는 MEMBER 프로퍼티을 위해 필요로 할 때 Qt 는 자동으로 시그널을 전달합니다.
  • REVISION number is optional. If included, it defines the property and its notifier signal to be used in a particular revision of the API (usually for exposure to QML). If not included, it defaults to 0.
  • REVISION 은 선택사항입니다. 만약 정해진다면 특정 API 에서 사용되는 알리미 시그널과 프로퍼티를 정의 합니다 (보통 QML 에 노출됩니다). 정해지지 않는다면 기본값은 0 입니다.
  • The DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., Qt Designer). Most properties are DESIGNABLE (default true). Instead of true or false, you can specify a boolean member function.
  • DESIGNABLE 속성은 GUI 디자인 도구 (예. Qt 디자이너) 에서 보여줘야할 프로퍼티 임을 가리킵니다. true 또는 false 값 대신에 boolean (값 반환) 형 맴버 함수를 지정할수 있습니다.
  • The SCRIPTABLE attribute indicates whether this property should be accessible by a scripting engine (default true). Instead of true or false, you can specify a boolean member function.
  • SCRIPTABLE 속성은 이 프로퍼티는 스크립팅 엔진을 통해 접근이 가능해야 한지를 가리킵니다(기본값 true).  true 또는 false 값 대신에 boolean (값 반환) 형 맴버 함수를 지정할수 있습니다.
  • The STORED attribute indicates whether the property should be thought of as existing on its own or as depending on other values. It also indicates whether the property value must be saved when storing the object's state. Most properties are STORED (default true), but e.g., QWidget::minimumWidth() has STORED false, because its value is just taken from the width component of property QWidget::minimumSize(), which is a QSize.
  • STORED 속성은 프로퍼티 스스로 독립적인 값으로 존재하는 것인지 아니면 다른 값들에 의존 하는 것인지를 지정해줍니다. 또한 객체의 상태를 저장할 때에 프로퍼티 값이 보존 되어야 하는지를 지정합니다. 대부분의 프로퍼티들은 STORED 속성이지만 (기본값 true), 예를 들어 QWidget::minimumWidth() 는 QSize 인 QWidget::minumumSize() 의 너비 요소에서 값을 가져가기 때문에, STORE 속성이 false 입니다. 
  • The USER attribute indicates whether the property is designated as the user-facing or user-editable property for the class. Normally, there is only one USER property per class (default false). e.g., QAbstractButton::checked is the user editable property for (checkable) buttons. Note that QItemDelegate gets and sets a widget's USER property.
  • USER 속성은 클래스를 위해 사용자가-조회하고 사용자가-편집할 수 있는 설계된 프로퍼티임을 가리킵니다. 일반적으로 클래스 (기본값 false) 마다 단 하나의 USER 프로퍼티만 있습니다. 예. QAbstractButton::checked 는 (checkable - 체크가능한) 버튼을 위한 사용자 편집가능한 프로퍼티입니다. QItemDelegate 는 위젯의 USER 프로퍼티를 읽거나 설정합니다.
  • The presence of the CONSTANT attibute indicates that the property value is constant. For a given object instance, the READ method of a constant property must return the same value every time it is called. This constant value may be different for different instances of the object. A constant property cannot have a WRITE method or a NOTIFY signal.
  • CONSTANT 속성의 존재는 해당 프로퍼티가 상수인지를 가리킵니다. 주어진 객체 인스턴스에 대해, 상수 프로퍼티의 READ 메소드는 반드시 매번 불렸을 때 같은 값을 반환해야합니다. 상수 프로퍼티는 (변경이 안되기 때문에 변경하거나 변경으로 인해 발생되는) WRITE 메소드나 NOTIFY 시그널을 가질 수가 없습니다.
  • The presence of the FINAL attribute indicates that the property will not be overridden by a derived class. This can be used for performance optimizations in some cases, but is not enforced by moc. Care must be taken never to override a FINAL property.
  • FINAL 속성의 존재는 해당 프로퍼티는 상속 받은 클래스에 의해 무효화(오버라이드) 가 되지 않을 것이라는 것을 가리킵니다. 이는 몇몇 클래스들에서 성능상 최적화를 위해 사용될 수 있습니다만, moc 에 의해 강요되지는 않습니다. FINAL 프로퍼티를 무효화 하지 않기 위해서는 조심해야 합니다.

The READWRITE, and RESET functions can be inherited. They can also be virtual. When they are inherited in classes where multiple inheritance is used, they must come from the first inherited class.

READ, WRITE 와 RESET 함수들은 상속 받을 수 있습니다. 또는 가상화 (가상 함수) 될 수 있습니다. 다중 상속이 일어나는 곳에서 상속이 발생될 때, 그들은 첫번째 상속 받는 클래스에서 나타나야 합니다.

The property type can be any type supported by QVariant, or it can be a user-defined type. In this example, class QDate is considered to be a user-defined type.

프로퍼티 자료형은 QVariant 의 지원 의해 어떤 자료형이라도 될 수 있거나, 사용자-지정된 자료형이 될 수 있습니다. 아래 예에서는 QDate 는 사용자-지정형으로 고려됩니다.

Q_PROPERTY(QDate date READ getDate WRITE setDate)

Because QDate is user-defined, you must include the <QDate> header file with the property declaration.

QDate 는 사용자-지정형이므로, 당신은 반드시 <QDate> 를 프로퍼티 선언과 함께, 헤더 파일을 포함해야 합니다.

For QMapQList, and QValueList properties, the property value is a QVariant whose value is the entire list or map. Note that the Q_PROPERTY string cannot contain commas, because commas separate macro arguments. Therefore, you must use QMap as the property type instead of QMap<QString,QVariant>. For consistency, also use QList and QValueList instead of QList<QVariant> and QValueList<QVariant>.

QMap, QList 와 QValueList 프로퍼티들에 대해서는, 전체 목록이나 지도가 값을 가지는 QVariant 형이 됩니다. 매크로 인수들을 구분하는 데 쉼표가 사용되므로, Q_PROPERTY 문자열에는 쉼표(, 콤마) 가 있어서는 안됩니다. 그러므로 QMap<QString, QVariant> 대신에 QMap 을 써야 합니다. 일관성을 유지하기 위해 QList<QVariant> 대신에 QList 를, QValueList<QVariant> 대신에 QValueList 을 사용해야 합니다.

Reading and Writing Properties with the Meta-Object System

메타-오브젝트 시스템에서 프로퍼티들을 읽고 쓰기

A property can be read and written using the generic functions QObject::property() and QObject::setProperty(), without knowing anything about the owning class except the property's name. In the code snippet below, the call to QAbstractButton::setDown() and the call to QObject::setProperty() both set property "down".

프로퍼티의 이름을 알고 있다면 클래스를 소유하고 있는 클래스의 정보들을 전혀 몰라도 제네릭(일반) 함수들인 QObject::property() 과 QObject::setProperty() 를 사용하면 프로퍼티를 읽고 쓸 수 있습니다. 아래 코드 스니펫(단편) 을 보면, QAbstractButton::setDown() 과 QObject::setProperty() 호출하는데서 모두 프로퍼티 "down" 을 지정하는 것을 볼 수 있습니다.

QPushButton *button = new QPushButton;
QObject *object = button;

button->setDown(true);
object->setProperty("down", true);

Accessing a property through its WRITE accessor is the better of the two, because it is faster and gives better diagnostics at compile time, but setting the property this way requires that you know about the class at compile time. Accessing properties by name lets you access classes you don't know about at compile time. You can discover a class's properties at run time by querying its QObjectQMetaObject, and QMetaProperties.

더 빠르고 컴파일 시점에서 더 좋은 진단정보를 제공하지만 프로퍼티를 이 방법으로 설정한다면 컴파일 시점에서 클래스를 당신이 알아야 하므로, WRITE 접근자를 통한 프로퍼티 접근이 위 두가지 보다 더 좋습니다. 이름만으로 프로퍼티에 접근한다는 것은 컴파일 시점 때에 모르는 클래스에 대해서 접근할 수 있게 해줍니다. 당신은 QObject, QMetaObject 와 QMetaProperties 를 사용하여 실행-중에 클래스의 프로퍼티들을 조회하여 정보를 확보 할 수 있습니다.

QObject *object = ...
const QMetaObject *metaobject = object->metaObject();
int count = metaobject->propertyCount();
for (int i=0; i<count; ++i) {
    QMetaProperty metaproperty = metaobject->property(i);
    const char *name = metaproperty.name();
    QVariant value = object->property(name);
    ...
}

In the above snippet, QMetaObject::property() is used to get metadata about each property defined in some unknown class. The property name is fetched from the metadata and passed to QObject::property() to get the value of the property in the current object.

위 스니펫에서는 QMetaObject::property() 가 알지 못하는 어떤 클래스에서 정의된 프로퍼티 각각에 대한 메타정보를 얻는데 사용되었습니다. 프로퍼티 이름은 메타정보에서 얻어지고, 현재 객체에 있는 프로퍼티의 값을 읽기 위해 QObject::property() 에게 전달됩니다.

A Simple Example

단순한 예제

Suppose we have a class MyClass, which is derived from QObject and which uses the Q_OBJECT macro in its private section. We want to declare a property in MyClass to keep track of a priority value. The name of the property will be priority, and its type will be an enumeration type named Priority, which is defined in MyClass.

예를 들어, QObject 를 상속한 MyClass 라는 클래스가 있으며, Q_OBJECT 매크로가 프라이빗(개인) 색션 가정합니다. 우리는 우선 순위 값을 추적하기 위해 MyClass 에 프로퍼티를 선언하고 싶습니다. 그 프로퍼티의 이름은 priority 라고 정해지고, 자료형은 열거형으로 MyClass 내에 정의된 Priority 로 지정될 것입니다

We declare the property with the Q_PROPERTY() macro in the private section of the class. The required READ function is named priority, and we include a WRITE function named setPriority. The enumeration type must be registered with the Meta-Object System using the Q_ENUM() macro. Registering an enumeration type makes the enumerator names available for use in calls to QObject::setProperty(). We must also provide our own declarations for the READ and WRITE functions. The declaration of MyClass then might look like this:

우리는 Q_PROPERTY() 매크로를 사용해 클래스의 프라이빗 영역에 프로퍼티를 선언합니다. 요구되는 READ 함수의 이름은 priority 이고, 우리는 setPriority 라는 WRITE 함수를 포함합니다. 메타-오브젝트 시스템에 등록되기 위해서는 열거형 자료는 반드시 Q_ENUM() 매크로를 사용해야 합니다. 열거형 자료를 등록함으로 열거형 자료형 이름은 QObject::setProperty() 에서 사용할 수 있습니다. 우리는 또한 우리만의 READ 와 WRITE 함수를 제공해야 합니다. 그렇게 하면 MyClass 의 선언을 아래와 같이 보일 수 있습니다:

class MyClass : public QObject
{
    Q_OBJECT
    Q_PROPERTY(Priority priority READ priority WRITE setPriority NOTIFY priorityChanged)

public:
    MyClass(QObject *parent = 0);
    ~MyClass();

    enum Priority { High, Low, VeryHigh, VeryLow };
    Q_ENUM(Priority)

    void setPriority(Priority priority)
    {
        m_priority = priority;
        emit priorityChanged(priority);
    }
    Priority priority() const
    { return m_priority; }

signals:
    void priorityChanged(Priority);

private:
    Priority m_priority;
};

The READ function is const and returns the property type. The WRITE function returns void and has exactly one parameter of the property type. The meta-object compiler enforces these requirements.

READ 함수는 const (상수) 형태이고 프로퍼티 형으로 반환해야합니다. WRITE 함수는 void 형을 반환하고 프로퍼티 형의 한 파라미터를 정확히 가집니다. 메타-오브젝트 컴파일러는 이들 요구사항들을 지키도록 요구합니다.

Given a pointer to an instance of MyClass or a pointer to a QObject that is an instance of MyClass, we have two ways to set its priority property:

MyClass 의 인스턴스인 QObject 를 가리키는 포인터나 MyClass 의 인스턴스를 가리키는 포인터가 주어 졌을때, 해당 클래스의 priority 형 프로퍼티를 설정하는데는 두가지 방법이 있습니다.

MyClass *myinstance = new MyClass;
QObject *object = myinstance;

myinstance->setPriority(MyClass::VeryHigh);
object->setProperty("priority", "VeryHigh");

In the example, the enumeration type that is the property type is declared in MyClass and registered with the Meta-Object System using the Q_ENUM() macro. This makes the enumeration values available as strings for use as in the call to setProperty(). Had the enumeration type been declared in another class, its fully qualified name (i.e., OtherClass::Priority) would be required, and that other class would also have to inherit QObject and register the enumeration type there using the Q_ENUM() macro.

이 예제에서, 프로퍼티 형으로 선언된 열거형 자료는 MyClass 에서 선언되고 Q_ENUM() 매크로를 사용해 메타-오브젝트 시스템에 등록되었습니다. 이는 setProperty() 를 부를 수 있게 하기 위해, 열거형 자료를 문자열로 만들어 줍니다. 또 다른 클래스에서 선언된다면, 전체 유효한 이름(다시 말하면, OtherClass::Priority) 이 요구되며, QObject 를 써서 상속 받은 다른 클래스는 마찬가지로 Q_ENUM() 매크로를 써서 열거형을 등록 해야 할 것입니다.

A similar macro, Q_FLAG(), is also available. Like Q_ENUM(), it registers an enumeration type, but it marks the type as being a set of flags, i.e. values that can be OR'd together. An I/O class might have enumeration values Read and Write and then QObject::setProperty() could accept Read | WriteQ_FLAG() should be used to register this enumeration type.

비슷한 매크로로 Q_FLAG() 또한 제공됩니다. Q_ENUM() 과 유사하게, 열거형 자료를 등록하지만, flags 의 묶음으로 자료형이 표기되는데, 다시 말해 이들 값들이 OR 연산으로 합쳐질 수 있습니다. I/O (입/출력) 클래스는 Read 와 Write 값을 열거형으로 가질 수 있으며, 그 때 QObject::setProperty() 에서 Read | Write 형태의 값을 받아들일 수 있게 할 수 있습니다. Q_FLAG() 는 이 열거형 자료를 등록하는데 사용되어야 합니다.

Dynamic Properties

동적 (다이나믹) 프로퍼티 

QObject::setProperty() can also be used to add new properties to an instance of a class at runtime. When it is called with a name and a value, if a property with the given name exists in the QObject, and if the given value is compatible with the property's type, the value is stored in the property, and true is returned. If the value is not compatible with the property's type, the property is not changed, and false is returned. But if the property with the given name doesn't exist in the QObject (i.e., if it wasn't declared with Q_PROPERTY()), a new property with the given name and value is automatically added to the QObject, but false is still returned. This means that a return of false can't be used to determine whether a particular property was actually set, unless you know in advance that the property already exists in the QObject.

QObject::setProperty() 는 실행 중에 클래스의 인스턴스 (객체) 에 대해 새 프로퍼티를 추가하는데에도 사용될 수 있습니다. 이름과 값으로 불려질 때에는 주어지는 이름이 QObject 에 존재해야하고, 프로퍼티의 자료형과 호환되는 값이 주어져야 합니다. 성공적으로 저장이 되면 true 값을 반환합니다. 만약 (저장할) 값이 프로퍼티의 자료형과 호환이 되지 않는다면 프로퍼티는 변경되지 않으며, false 값을 반환 합니다. 그런데, 주어진 이름이 QObject 에 존재하지 않는다면 (다시 말에 Q_PROPERTY() 내에 선언되지 않았다면), 주어진 이름으로 새 프로퍼티와 값이 자동으로 QObject 에 추가가 되겠지만, false 값이 반환 됩니다. 이는 QObject 내에 그 프로퍼티가 있는지 사용자가 미리 알지 않으면, 지정한 프로퍼티가 실제로 설정 되었는지 결정되는데 반환 되는 값만으로는 알 수 없기 때문입니다.

Note that dynamic properties are added on a per instance basis, i.e., they are added to QObject, not QMetaObject. A property can be removed from an instance by passing the property name and an invalid QVariant value to QObject::setProperty(). The default constructor for QVariant constructs an invalid QVariant.

동적 프로퍼티들은 인스턴스 (객체) 기반으로 추가됩니다. 다시 말해 QMetaObject 가 아닌 QObject 에 추가가 됩니다. 지정된 프로퍼티의 이름과 유효하지 않은 QVariant 값을 QObject::setProperty() 에게 전달하면 해당 프로퍼티는 제거될 수 있습니다. QVariant 의 기본 생성자를 쓰면 유요하지 않는 QVariant 를 만들어 냅니다.

Dynamic properties can be queried with QObject::property(), just like properties declared at compile time with Q_PROPERTY().

동적 프로퍼티들은 Q_PROPERTY() 을 사용했을 때 컴파일 시점에 선언된 프로퍼티들과 마찬가지로 QObject::property() 에서 질의가 가능합니다.

Properties and Custom Types

프로퍼티들과 사용자 정의형

Custom types used by properties need to be registered using the Q_DECLARE_METATYPE() macro so that their values can be stored in QVariant objects. This makes them suitable for use with both static properties declared using the Q_PROPERTY() macro in class definitions and dynamic properties created at run-time.

프로퍼티에 의해 사용되는 사용자 정의 자료형은 Q_DECLARE_METATYPE() 매크로를 사용해서 등록하여, 그들의 값들이 QVariant 객체에 저장될 수 있게 합니다. 이는 Q_PROPERTY() 매크로를 사용해서 정적 프로퍼티들이나 실행-중에 생성되는 동적 프로퍼티들 둘 다 맞게 사용되게 해줍니다.

Adding Additional Information to a Class

클래스에 추가적인 정보를 달기

Connected to the property system is an additional macro, Q_CLASSINFO(), that can be used to attach additional name--value pairs to a class's meta-object, for example:

연결된 프로퍼티 시스템에서 Q_CLASSINFO() 라는 추가적인 매크로는 추가로 이름-값을 쌍으로 해서 클래스의 메타-오브젝트에 붙이는데 사용될 수 있습니다. 예를 들면:

Q_CLASSINFO("Version", "3.0.0")

Like other meta-data, class information is accessible at run-time through the meta-object; see QMetaObject::classInfo() for details.

다른 메타-데이터처럼, 클래스 정보는 메타-오브젝트를 사용해 실행-중에 접근할 수 있습니다. QMetaObject::classInfo() 에서 자세한 정보를 확인 바랍니다.

See also Meta-Object SystemSignals and SlotsQ_DECLARE_METATYPE(), QMetaType, and QVariant.

같이 보기 Meta-Object SystemSignals and SlotsQ_DECLARE_METATYPE(), QMetaType, 과 QVariant.

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