What worries me is that. The following should work: Note that you also have to call qRegisterMetaType<MyMpiMessage> (); before you use the function the first time. Use it if you want to use it as a global enumerator and then you need to call the meta-type runtime registration from the library, not from the application. An alternative would be to wrap shared_ptr<int> in your own class and implement comparison the way you want. By convention, these files are given a . Q_DECLARE_METATYPE(MyClass); qRegisterMetaType<MyClass>(); I can use the type in queued connection with signals like this one: void MySignal(MyType o); Now I also would like to use the type with signals like this: void MyVectorSignal(QVector<MyType> v);Qt 5. qRegisterMetaType vs. In my project, MyClass is a cache for multi-dimensional data "point", and it looks like: class MyClass { public: MyClass(); /* Some functions */ private: int m_index; double m_time; QList<int> *m_data; };Firstly, you shouldn't need to use Q_DECLARE_METATYPE (or qRegisterMetaType) with the enum at all, this is handled by the moc. Obviously, a call to qRegisterMetaType<T>(. Thanks for the suggestion. rep file extension, short for Replica. See full list on doc. template <typename T> struct QMetaTypeId<Container<T>>. cpp. QMetaType::type () is a bit slower, but compilation succeeds if a type is not registered. 4. 4] QString QWebSocket:: subprotocol const. qRegisterMetaType() docs say: Any class or struct that has a public constructor, a public copy constructor, and a public destructor can be registered. " Yet types like QVariantMap are themself typedefs. Q_DECLARE_METATYPE QMetaType::type. Type is not registered, please use the Q_DECLARE_METATYPE macro to make it known to Qt's meta-object system. c:55 This looks like some loader initialization mismatch, check debug vs release builds of your application and libraries that are used. 基本理解. See also state() and Creating Custom Qt Types. This function was introduced in Qt 4. If you want both, then register both. . Q_DECLARE_METATYPE only registers a type in meta type system. Alt. {. Then after some time, we can begin answering them. 2. By the way, Qt 4. Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. It looks like one can register a type more than once, specifying different typenames, i. Tried proposed solution using QVariant::fromValue, but kept getting compiler errors of type: . With Q_DECLARE_METATYPE and without qRegisterMetaType: No warning, slot is called With Q_DECLARE_METATYPE and with qRegisterMetaType: No warning, slot is called. The docs only talk about class or struct with public default constructor, copy constructor and. Q&A for work. It associates a type name to a type so that it can be created and destructed dynamically at run-time. qRegisterMetaType vs. Q_DECLARE_METATYPE(MyStruct) Q_DECLARE_METATYPE(MyList) QDBusArgument &operator<<(QDBusArgument &, const MyStruct&);. However, as you need the type to be. Macros Detailed Description The QMetaType class manages named types in the meta-object system. Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. Any class or struct that has a public constructor, a public copy constructor, and a public destructor can be registered. c:55 This looks like some loader initialization mismatch, check debug vs release builds of your application and libraries. The logical equivalent of a const T &r (reference to const T) is a const T * const p (const pointer to const T). Any class or struct that has a public default constructor, a public copy constructor, and a. In fact, all Qt classes derived from QObject (direct or indirect) use this macro to declare their copy constructor and assignment operator to be private. As said in int qRegisterMetaType () documentation: To use the type T in QVariant, using Q_DECLARE_METATYPE () is sufficient. Here you can see that the macro expands to nothing. I store them in QVariant :. There's no need to call qRegisterMetaType that many times, once is enough. Obviously then you would not do registerComparator (). It associates a type name to a type so that it can be created and destructed dynamically at run-time. Now, that Q_DECLARE_METATYPE enables the type for Qt template classes and QVariant. The Q_DECLARE_METATYPE () macro also makes it possible for these values to be used as arguments to signals, but only in direct signal-slot connections. Make a typedef for QSharedPointer<UserDataType>, and use both Q_DECLARE_METATYPE as well as qRegisterMetaType () to register it for use. I need to call the Q_DECLARE_METATYPE() to pass the smart pointer. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections. Registered enumerations are automatically registered also to the Qt meta type system, making them known to QMetaType without the need to use. When I emit a signal, then I get next error to the output stream:. c:55 This looks like some loader initialization mismatch, check debug vs release builds of your application and libraries that are used. Note that if you intend to use the type in queued signal and slot connections or in QObject's property system, you also have to call qRegisterMetaType() since the names are resolved at runtime. There's also no need for that typedef, it only makes the code less readable. 0. Data Type Conversion Between QML and C++. Note that if you intend to use the type in queued signal and slot connections or in QObject 's property system, you also have to call qRegisterMetaType () since the names are resolved at runtime. Improve this answer. You can make them known ( Q_DECLARE_METATYPE ), however you can't register them as QML type. struct StandardData { int EmpId; QString Name; }; Q_DECLARE_METATYPE (StandardData) Additionally, you might need to call qRegisterMetaType. To make the type known to this class, we invoke the Q_DECLARE_METATYPE () macro on the class in the header file where it is defined: This now makes it possible for Message values to be stored in QVariant objects and retrieved later. It is often easier and cleaner to define an ENUM inside a class (see ENUM), but if you need a standalone enum type, using the ENUM keyword outside of a class definition can be. In the header, after the class declaration, outside the namespace, I've included. You should use qmlRegisterType function for that. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections. Also, Q_DECLARE_METATYPE(MyNamespace::MyType) should be in the header declaring MyType so that you don't have to repeat it all over again and again. This function was introduced in Qt 4. Even though we do not intend to use the type with QVariant in this example, it is good practice to also declare the new type with Q_DECLARE_METATYPE (). See also state(). 9k 9 34 52. c:55 This looks like some loader initialization mismatch, check debug vs release builds of your application and libraries. It is more or less explained in the manual for int qRegisterMetaType (const char *typeName) This function requires that T is a fully defined type at the point where the function is called. [override virtual] bool QLocalSocket:: waitForBytesWritten (int msecs = 30000) Reimplements:. Posted by Unknown at 2:06 AM. :) QApplication is the root QObject of the program and its full initialization is required before anything can practically be done with anything else. As G. It seems that for a metatype that is a QList<MyClass::MyEnum> I must. If you want to pass IBase * between different threads, you need to register class with qRegisterMetaType<IBase *> () call; It is bad practice to pass pointers throught singals, because it is hard to control lifetime of passed objects. Consider the specific case of qRegisterMetaType. Re: How to use Q_DECLARE_METATYPE. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections. before saveload operation would happen. From the docs: int qRegisterMetaType ( const char * typeName ) Registers the type name typeName to the type T. Q_DECLARE_METATYPE is required to store type with QVariant, those two are required to register object's "big three" to manage it as resource and its serialization methods. Declare new types with Q_DECLARE_METATYPE () to make them available to QVariant and other template-based functions. That always worked in Qt4, but in Qt5 I get the following error: @error: specializing member ‘::qRegisterMetaType<Subclass>’ requires ‘template<>’ syntax@. Using Q_ENUM () allows you to retrieve at run-time. Learn more about Teams I can't figure out a way to automatically declare a meta type, i. To start viewing messages, select the forum that you want to visit from the selection below. It is only useful to the code that follows it, in the same file. Here you can see that the macro expands to nothing. Any idea what I'm missing please? BTW, no problem at all using Schedule in QMetaProperty or QVariant. cpp 中,用connect函数 将抛出此结构体的信号和接收此结构体的槽函数关联之前,要调用qRegisterMetaType. The class is used to send arguments over D-Bus to remote applications and to receive them back. QMetaType::type () returns the same ID as qMetaTypeId (), but does a lookup at runtime based on the name of the type. 5 is compiled with GCC 4. This function returns the Qt meta type id for the type (the same value that is returned from qRegisterMetaType()). 能猜到原因吗?注意看前面 Q_DECLARE_METATYPE() 代码, 对了。类中的成员函数qt_metatype_id中包含对qRegisterMetaType(typeName)的调用: 这儿就是辗转调用了这个带参数的qRegisterMetaType函数: unregisterType(const char *typeName) 函数的作用是取消自己先前注册的某个metatype类型。 and a Context class that holds an instance of MyGadget and exposes a pointer to it to QML via a Q_PROPERTY: #include <QObject> #include "mygadget. void QLocalSocket:: abort ()The Qt docs make it clear that to use a custom type with Queued Connections, I need to use both Q_DECLARE_METATYPE and qRegisterMetaType. Note: This function is thread-safe. We will still need to register it with the meta-object system at run-time by calling the qRegisterMetaType () template function before we make any signal-slot connections that use this type. The issue here is that Q_OBJECT forbids the copy and assignment constructors. F. You could try using registerConverter () to allow implicit conversion of the shared_ptr<int> to a regular int, and compare them that way. Connect and share knowledge within a single location that is structured and easy to search. 1. uint64; If this is your first visit, be sure to check out the FAQ by clicking the link above. Believing an Question from 2010 and the Qt Documentation, the operator==() doesn't work with custom types. I want to use my objects as QVariants and for queued connections. The default access for a class is private, so that Container* data();. That said, your stack trace is really strange: _dl_debug_initialize (ldbase=4294967292, ns=1095236752) at dl-debug. With Q_DECLARE_METATYPE and without qRegisterMetaType: No warning, slot is called With Q_DECLARE_METATYPE and with qRegisterMetaType: No warning, slot is called. If the type was not declared with Q_DECLARE_METATYPE (), compilation will fail. Use Q_DECLARE_OPAQUE_POINTER () to be able to register pointers to forward. Also, to use type T with the QObject::property () API,. type() typeName() PySide6. 2 Answers. I read a bit and it seems that Q_DECLARE_SMART_POINTER_METATYPE is supposed to allow this to work. I have a const pointer to a class derived from qobject and want to put into QVariant like below: QVariant::fromValue(objectPointer) I have declared the meta type of derived class using: Q_DECLARE_METATYPE(const QDrivedClass *) in the header file (. Detailed Description. qRegisterMetaType is also called in the class constructor. Qt5でシグナルの引数としてユーザー定義型を指定する場合は、 Q_DECLARE_METATYPE と qRegisterMetaType () を使って方の登録を行う必要が. 2 Answers. [virtual] QAbstractSocket:: ~QAbstractSocket Destroys the socket. The other overload around has almost the same form but for the fact that it. QMetaType. namespace CCS { Q_DECL_EXPORT Q_NAMESPACE. See also. Using the Q_DECLARE_METATYPE () macro 2. Returns the internal ID used by QMetaType. To register. The QML engine provides built-in support for a. See the Qt D-Bus Type System page for more information on the type system. QVariantList , QString (if the list contains exactly one item) Casting between primitive type (int, float, bool etc. It associates a type name to a type so that it can be created and destructed dynamically at run-time. Also Q_DECLARE_METATYPE does not register a type, but declares it. But I can't see a method to insert myClass into. Yes, templated types can be used in Qt signal/slots. Any class or struct that has a public default constructor, a public copy. This macro is used to specialise the template class QMetaTypeId with typename TYPE, in which, a static member function qt_metatype_id () is defined. [quote author="Andre" date="1306394817"]In that case, I think you need to register them. I am also using some in queued signal and slot connections. QMetaType registerNormalizedTypedef normalizedTypeName, type: metaType ); return. Any class or struct that has a public default constructor, a public copy constructor, and a. The class is used as a helper to marshall types in QVariant and in queued signals and slots connections. Step 2 (meta type Declare macro), if needed, describe your custom type/class to things like QVariant, QDebug and other "support" systems used everywhere on QObjects. ) is supported. You can create Q_GADGETS in QML using a C++ factory object registered to be accessible in QML, and a Q_INVOKABLE function in this factory which returns an instance of the Q_GADGET object. Qt5でシグナルの引数としてユーザー定義型を指定する場合は、Q_DECLARE_METATYPEとqRegisterMetaType()を使って方の登録を行う必要がある。Trying to register std::map<non_template_type_1,non_template_type_2> with Q_DECLARE_METATYPE() results in compilation failure and apparently is not supported. You may have to register before you can post: click the register link above to proceed. 14 vs 5. I guess it's the qRegisterMetaType () call itself that's missing. Read and abide by the Qt Code of Conduct. See also state() and Creating Custom Qt Types. There's also no need for that typedef, it only makes the code less readable. The class is used as a helper to marshall types in QVariant and in queued signals and slots connections. You may have to register before you can post: click the register link above to proceed. There's no need to call qRegisterMetaType that many times, once is enough. QtNetwork. call qRegisterMetaType with the name specified, else reading properties. Accessing an enum stored in a QVariant. The ones I am registering for are mostly structs for storing data and just a few simple classes. 如果非QMetaType内置类型要. Registered enumerations are automatically registered also to the Qt meta type system, making them known to QMetaType without the need to use Q_DECLARE_METATYPE(). To start viewing messages, select the forum that you want to visit from the selection below. That's created by this macro. The class in Qt responsible for custom types is QMetaType. by using qRegisterMetaType(). Please note that I do not use Q_DECLARE_METATYPE on purpose because I don't actually need its features (QVariant expansion) right now. 如果要使自定义类型或其他非QMetaType内置类型在QVaiant中使用,必须使用该宏。. I am also using some in queued signal and slot connections. @Q_DECLARE_METATYPE (std::unique_ptr<Thing>);@. } But you'll most likely need to abstract the Q_DECL_EXPORT part so it is a Q_DECL_IMPORT in right circumstances, as described in Creating Shared Libraries. 14. ) QObject::connect: Cannot queue arguments of type 'QVector<int>'. The same plugin may be loaded multiple times during the application's lifetime. x however, the code generated by moc will call qRegisterMetaType for you if moc can determine that the type may be registered as a. type() typeName() PySide6. QVariantList MyClass::getFooCollection (void) const { QVariantList list; for (const auto& l: fooCollection_) { list. See the Custom Type Example for code that demonstrates this. It associates a type name to a type so that it can be created and destructed dynamically at run-time. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. [virtual] QLocalSocket:: ~QLocalSocket Destroys the socket, closing the connection if necessary. Any class or struct that has a public constructor, a public copy constructor, and a public destructor can be registered. Q_DECLARE_METATYPE(MyClass*); That's how Qt handles it with QObject and QWidget. 被 Q_DECLARE_METATYPEQ 标记的类型可以让Q MetaType 查询到类型,也可以让QVariant识别到。 struct MyStruct { QString name; }; Q_DECLARE_METATYPE(MyStruct) 若对象包含在自定义的命名空间中时,注册时要带上完整的命令空间. Qt is throwing an exception because it doesn't know how to store the shared_ptr onto a QDataStream. I also don't want to use qRegisterMetaType, since it is run-time bound. What worries me is that. Call qRegisterMetaType() to make type available to non-template based functions, such as the queued signal and slot connections. e. If \c MyStruct is in a namespace, the Q_DECLARE_METATYPE () macro. Without this reference, it compiles just fine. append (QVariant::fromValue (l)); } return list; } The metatype system declaration and registration you have. Returns the used WebSocket protocol. no unexpected garbage. 1. You may have to register before you can post: click the register link above to proceed. I think you should consider making the signal/slot parameter be const QVector<int>& dataSet. For those who follow. I pass the MyClass pointer to the streaming operator and only stream things like QString, QPointF, etc. When data values are exchanged between QML and C++, they are converted by the QML engine to have the correct data types as appropriate for use in QML or C++. c:55 This looks like some loader initialization mismatch, check debug vs release builds of your application and libraries. cpp. ", which suggests it is only for classes and structs. 1 Answer. qRegisterMetaType vs. That. All I want to do is be able to convert this to a byte array in order to send on a socket, and get the object back (deserialize) on the other end. Once they're known you can use them, but you can't create them on the QML side. The. Declare new types with Q_DECLARE_METATYPE () to make them available. Detailed Description. The third without Q_DECLARE_METATYPE. QML Qvariant from custom class. As you already have a typedef for your type, you can simply use Q_DECLARE_METATYPE as in the following example: #include <QtCore> template <typename T> struct Proxy { T data; }; typedef Proxy<QImage> TrayType; Q_DECLARE_METATYPE (TrayType) class Donor : public. 1)引入头文件:#include<QMetaType>. QVariant’s operator== now uses QMetaType::equals for the comparison. Registers the type name . // But the split allows to. Note that if you intend to use the type in queued signal and slot connections or in QObject 's property system, you also have to call qRegisterMetaType () since the names are resolved at runtime. This function was introduced in Qt 6. void QLocalSocket:: abort ()The signal "orientationChanged" includes an enum of type "Orientation" to indicate if the card has been turned up or down. int videoSourceMetaTypeId = qRegisterMetaType< VideoSource > ();QAbstractSocket::SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType(). D-Bus offers an extensible type system, based on a few primitive types and associations of them. Qt Base (Core, Gui, Widgets, Network,. Hello Ladies and Gentlemen. The macro will register your variable with the Qt Meta-Object System, which will allow you to. It must appear in a code block. fromValue <QList<double> > ( x1); To copy to clipboard, switch view to plain text mode. : Q_DECLARE_METATYPE(MyClass*); That's how Qt handles it with QObject and QWidget. Similarly you can create a mutable view of type QAssociativeIterable on any container registered with Q_DECLARE_ASSOCIATIVE_CONTAINER_METATYPE(). From the QVariant::value documentation: If the QVariant contains a pointer to a type derived from QObject then T may be any QObject type. 2. However Q_DECLARE_METATYPE () is a bit more complicated. hpp which is included in Class1. @SGaist Yes, I am using it with QVariant, mostly with QSettings to save and retrieve data easily by overriding QDataStream operators. Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. How: I linked qRegisterMetaType. Note that for enum types, you no not even need to call qRegisterMetaType () in these cases. Any class or struct that has a public default constructor, a public copy constructor, and a. Enum has been moved from outside of the class to inside of it. [virtual] QAbstractSocket:: ~QAbstractSocket Destroys the socket. One way to work around this is for example having a helper class (singleton or context property) with. Note: it's also safe to call qRegisterMetaType () multiple times. Consider the specific case of qRegisterMetaType. // This primary template calls the -Implementation, like all other specialisations should. Call qRegisterMetaType () to make type available to non-template based. You may have to register before you can post: click the register link above to proceed. Re: Q_DECLARE_METATYPE vs qRegisterMetaType for non global namespace classes (QTest) The reason for this behavior might be caused by the fact that runtime signal/slot connections are checked by string manipulation - both Q_DECLARE_METATYPE, SIGNAL, SLOT macros and 'moc' are (among other things) converting type-names to text and pass it along. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections. An alternative would be to wrap shared_ptr<int> in your own class and implement comparison the way you want. There's no need to call qRegisterMetaType that many times, once is enough. This is not the case, since the following succeeded: @QMetaType::type("MyClass"); // success@. This version of the function is to register alias types. QAbstractSocket::SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType(). Q_DECLARE_METATYPE vs qRegisterMetaType for non global namespace classes. akshatrai91 7 Jan 2021, 06:21. c:55 This looks like some loader initialization mismatch, check debug vs release builds of your application and libraries. Even though we do not intend. The fix is probably to include qsslsocket. Constantin. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. You may have to register before you can post: click the register link above to proceed. Re: Qt warning of type conversion already registered Originally. You can create Q_GADGETS in QML using a C++ factory object registered to be accessible in QML, and a Q_INVOKABLE function in this factory which returns an instance of the Q_GADGET object. Q_DECLARE_METATYPE ( blabla* ) Also qRegisterMetaType<T> () is only required for sending your object through queued signal/slot connections. Secondly, your linker (MSVC) complains that it can't find the metaObject for your ErrorHandler enum, which is normal as it is not exported from the. 0. That's probably there, as qRegisterMetaType () wouldn't compile otherwise. The class is used as a helper to marshall types in QVariant and in queued signals and slots connections. 3. All I want to do is be able to convert this to a byte array in order to send on a socket, and get the object back (deserialize) on the other end. So my first idea:. In Qt, you can declare a variable in two ways: 1. and Q_DECLARE_METATYPE uses qRegisterMetaType() internally. The documentation for exposing C++ properties to QML says that: "Note: Do not use typedef or using for Q_PROPERTY types as these will confuse moc. hi, I always after application running, receive debug text of: QObject::connect: Cannot queue arguments of type 'MyStruct'. However, I cannot figure out how to verify that the included parameter is FACE_UP or FACE_DOWN. (Make sure 'QVector<int>' is. Even though we do not intend to use the type with QVariant in this example, it is good practice to also declare the new type with Q_DECLARE_METATYPE (). Connect and share knowledge within a single location that is structured and easy to search. To enable using the type in queued signals and such, there also needs to be a corresponding call: qRegisterMetaType<foo::FooState>(); Question. hpp and qRegisterMetaType<quint32>("quint32"); in both the Constructors of Class1 and Class2. The file (called a "rep" file) uses a specific (text) syntax to describe the API. That said, your stack trace is really strange: _dl_debug_initialize (ldbase=4294967292, ns=1095236752) at dl-debug. Also, to use type T with the QObject::property () API, qRegisterMetaType () must be. }; Q_DECLARE_METATYPE (MyCustomType); Then in my application, I have a signal "void sendMsg (MyCustomType)" and I qRegisterMetaType (). However, if you want to use a type in a pure runtime context, for example in a QML document, the Qt runtime doesn't know the type declared with Q_DECLARE_METATYPE. The object it returns should also be a member of the factory class. // - in a header: // - define a specialization of this template calling an out-of. This allows us to use the Enum as a custom-type of a QVariant, to pass it between QML and Qt, to use it in synchronous signal-slot connections, and to print the symbolic enums (instead of a magic number) with qDebug(). 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. Firstly, you shouldn't need to use Q_DECLARE_METATYPE (or qRegisterMetaType) with the enum at all, this is handled by the moc. (Make sure 'MyStruct' is registered using qRegisterMetaType (). See also state() and Creating Custom Qt Types. . The documenation of this macro gives. Your code should look like this: Q_ENUM (StateEnum) //note the missing 'S' here Q_PROPERTY (StateEnum state READ state NOTIFY stateChanged) Share. cpp I have to do: qRegisterMetaType<Pkg>("Pkg"); and this does not give errors too, but when I try to create a QVariant(Pkg) I get lots of errors like:cardio63 26 Jan 2016, 10:19. ) which are updated by simulation code. Q_DECLARE_METATYPE on the other hand is (as far as I know) preprocessor bound. I tried and it looks like it's possible to register an enum type with Q_DECLARE_METATYPE or qRegisterMetaType and use it the same way. h. When using signals and slots with multiple threads, see Signals and Slots Across Threads. 0. QLocalSocket. Share Improve this answer Follow answered Jul 23, 2014 at 15:37. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections. Qt Remote Objects Compiler. Q_DECLARE_METATYPE与qRegisterMetaType学习. This may make certain type comparisons fail. So I am doing this: Qt Code: Switch view. 文章目录 Q_DECLARE_METATYPE qRegisterMetaType Q_DECLARE_METATYPE 使用Q_DECLARE_METATYPE标记自定义类型,可以让QMetaType查询到类型,也可以让QVariant识别。 qRegisterMetaType 在main函数中使用qRegisterMetaType注册自定义类型到元对象系统中,可在跨线程的信号槽中进行参数传递。I'm using Qt5 and qRegisterMetaType is not documented anymore, so I'm not sure if it's deprecated. I have created an qt bugticket hoping the documentation will be extended. From the docs: int qRegisterMetaType ( const char * typeName ) Registers the type name typeName to the type T. Q_DECLARE_METATYPE. If you ever wondered what does Q_DECLARE_META_TYPE or qRegisterMetaType do and when to use (or not to use) them, read on. Then you should register your object to use it with QML. the type name must be specified without the class, as in. Now I want to read this property with Qt's meta object system. To make the type known to this class, we invoke the Q_DECLARE_METATYPE () macro on the class in the header file where it is defined: Q_DECLARE_METATYPE(Message); This now makes it possible for Message values to be stored in QVariant objects and retrieved later. The QMetaType class manages named types in the meta-object system. The code compiles and runs ok. qRegisterMetaType<Subclass> ("Subclass") also doesn't work. 8. since it is a runtime registration. When I try to simply connect signalslot with such QVector as argument programm tells during run that this metatype should be registered (though QVector, QSharedPointer and class inherited from QObject should be registered automatically. cpp. 1 Answer. Q_DECLARE_METATYPE QMetaType::type. jsulm Lifetime Qt Champion @shivaVMC last edited by . qRegisterMetaType vs. cpp I have to do: qRegisterMetaType<Pkg>("Pkg"); and this does not give errors too, but when I try to create a QVariant(Pkg) I get lots of errors like:cardio63 26 Jan 2016, 10:19. cpp. Additional types can be registered using qRegisterMetaType() or by calling registerType(). 4] QString QWebSocket:: subprotocol const. I am also using some in queued signal and slot connections. Q_DECLARE_METATYPE. cpp. I have a few instances of QVector<MyClass> which I want them to be exposed to QScriptEngine.