Qt first impression - attribute

xiaoxiao2021-03-06  41

QT's properties: and C # Similar, Qt provides "Get", "Set" shortcuts --Property, which is used for data members, (function member mode definition). C # use the GET, SET method to reach the "Data Membership Definition" attribute; Qt uses normal function members Q_Property macro, completion properties, and metadata (simply: is the information of information about classs that can be viewed at runtime);

<*. h>

......

Q_Property (Type Name ReadFunction [Write SetFunction] [Designable Bool] [Scriptable Bool] [Stored Bool])

/ * Q_Property Macro: Register the information such as a metaobject (QMetaObject), QMetaObject class: Provide a range of methods, queries, modify the registered information (such as: attribute, enumeration, inheritance, class name, signal, slot); The QObject class uses QMetaObject to query, modify the properties, and also a method of "running operation class properties"; Name is used for QObject Get, set attributes; read is required, different with C # (C # can Only define only write properties); * /

Public: void setFunction (Type); // Parameter (or return value of the following GET function) can be qvariant inherited, // can also be enum, but must be registered with Q_enums (MyEnum ...) Elephant. Type getfunction () const; void resetFunction (); private: type n; ......

<*. CPP> ... Void myclass :: setFunction (type name) {n = name;} type myclass :: getFunction () const {return n;} void myclass :: resetFunction () {n = defaultname;} ......

Method 1: myclass * mc = ...; mc-> setfunction (value); mc-> getFunction ();

Method Two:

QOBJECT * QO = ...; Qo-> setProperty ("name", value); Qo-> getProperty ("name");

In addition to the above mentioned, QT's meticide also provides some other stuff: macro: q_objectq_propertyq_enumsq_classInfoq_override

Tr () and Trutf8 () two functions are string translations for internationalization

转载请注明原文地址:https://www.9cbs.com/read-75962.html

New Post(0)