qRegisterMetaType
时间: 2023-12-22 16:06:26 浏览: 30
qRegisterMetaType is a Qt function that registers a new meta type in the Qt meta-object system. Meta types are used to store user-defined data types in QVariant objects and to pass them between different parts of a Qt application.
The qRegisterMetaType function takes the name of the new type as a string and returns an integer representing the unique ID of the new type. This ID can then be used to create new instances of the type, store them in QVariant objects, and pass them around in signals and slots.
Example usage:
```
#include <QMetaType>
class MyCustomType {
public:
MyCustomType() {}
// ...
};
int main(int argc, char *argv[])
{
qRegisterMetaType<MyCustomType>("MyCustomType"); // Register new meta type
// ...
return 0;
}
```
In this example, a new type called "MyCustomType" is registered using the qRegisterMetaType function. This allows instances of MyCustomType to be stored in QVariant objects and passed around in signals and slots.