Than I did read this copy constructor of derived QT class and the answer by BЈовић. This fixed the issue. 2 Answers. Thus you need to use the runtime check QMetaType::type (). 4 which does not support all C++11 features. 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(). The class in Qt responsible for custom types is QMetaType . F. [override virtual] bool QAbstractSocket:: waitForBytesWritten (int msecs = 30000) Reimplements:. You can register a class pointer as the metatype, though. 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. Call qRegisterMetaType() to register the data type before you establish the connection. QAbstractSocket::SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_REGISTER_METATYPE() and qRegisterMetaType(). Using Qt 3D with QCustomPlot. To start viewing messages, select the forum that you want to visit from the selection below. 0. qRegisterMetaType<Subclass> ("Subclass") also doesn't work. Any class or struct that has a public default constructor, a public copy constructor, and a. Read and abide by the Qt Code of Conduct. I have declared all the types with Q_DECLARE_METATYPE, Q_OBJECT and the properties with Q_PROPERTY with the proper getters and setters. That said, your stack trace is really strange: _dl_debug_initialize (ldbase=4294967292, ns=1095236752) at dl-debug. statement to the header file containing. ) I got the hint "expected a declaration" when I tried to use qRegisterMetaType from the global scope in my cpp file. Q_DECLARE_METATYPE ( blabla* ) Also qRegisterMetaType<T> () is only required for sending your object through queued signal/slot connections. The class is used as a helper to marshall types in QVariant and in queued signals and slots connections. This may make certain type comparisons fail. Yes, templated types can be used in Qt signal/slots. 14. 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. Returns the used WebSocket protocol. qRegisterMetaTypeしているにもかかわらずQObject::connectでランタイムエラーが出る場合の回避策. When I emit a signal, then I get next error to the output stream:. 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. You had to use QMetaType::registerComparators () and the other static register functions in QMetaType to actually make use of that functionality, though. Q_DECLARE_METATYPE(TYPEDEF) Q_DECLARE_METATYPE(TYPEDEF) mainwindow. in a header file and call @qRegisterMetaType<std::unique_ptr<Thing>> ();@ before your signal and slots are used. 如果是指针类型他需要有完整的定义。使用Q_DECLARE_OPAQUE_POINTER()去注册指针用于转发数据类型。 使用Q_DECLARE_METATYPE()可以让这个数据类型T放到QVariant里面。如果想以队列的方式让T使用信号与槽,当第一次连接的时候就要调用qRegisterMetaType<T>()。Detailed Description. This has been changed, and isNull () now only returns true if the QVariant is empty or contains a nullptr. See also state () and Creating Custom Qt Types . 2. To start viewing messages, select the forum that you want to visit from the selection below. no unexpected garbage. You could try using registerConverter () to allow implicit conversion of the shared_ptr<int> to a regular int, and compare them that way. QtCore. The Custom Type, Custom Type Sending and Queued Custom Type examples show how to implement a custom type with the features outlined in this document. Make sure you call it from within a method. You may have to register before you can post: click the register link above to proceed. If you only want to store pointer to Foo with the metatype system, then use qRegisterMetaType<Foo *> ();. @Wieland Thanks. Call qRegisterMetaType() to make type available to non-template based functions, such as the queued signal and slot connections. There's also no need for that typedef, it only makes the code less readable. 被 Q_DECLARE_METATYPEQ 标记的类型可以让Q MetaType 查询到类型,也可以让QVariant识别到。 struct MyStruct { QString name; }; Q_DECLARE_METATYPE(MyStruct) 若对象包含在自定义的命名空间中时,注册时要带上完整的命令空间. The Q_DECLARE_METATYPE() macro and qRegisterMetaType() function documentation contain more detailed information about their uses and limitations. Q_DECLARE_METATYPE(TYPEDEF) Q_DECLARE_METATYPE(TYPEDEF) mainwindow. There's also no need for that typedef, it only makes the code less readable. Also you may need to use qRegisterMetaType function. このケースでも、Q_DECLARE_METATYPE(QSharedPointer<MyObject>)の宣言と、qRegisterMetatype<QSharedPointer<MyObject>>()の呼び出しが必要になる。 上のサンプルでは、同じsignalに対して2回connectを実行している。 The correct syntax is Q_DECLARE_METATYPE (std::string) without the ;. If the type was not declared with Q_DECLARE_METATYPE (), compilation will fail. 0. To register. 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. There's no compile time error, but when I run. 12. 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. To start viewing messages, select the forum that you want to visit from the selection below. This example is meant to declare and register only the pointer type of a given class: In conclusion: Don't use Q_DECLARE_METATYPE and qRegisterMetaType for your QObject enum. To enable creation of objects at run-time, call the qRegisterMetaType() template function to register it with the meta-object system. I pass the MyClass pointer to the streaming operator and only stream things like QString, QPointF, etc. I am also using some in queued signal and slot connections. To make the custom type. . Any class or struct that has a public default constructor, a public copy. See also. QMetaType. the type name must be specified without the class, as in. If the type was not declared with Q_DECLARE_METATYPE (), compilation will fail. Q_DECLARE_METATYPE vs qRegisterMetaType for non global namespace classes. Assuming base and derived are Q_GADGETs you want to get a static member. Is your Q_DECLARE_METATYPE in a header file or an implementation file? Incidentally, there is a mistake in TreeItem. With Q_DECLARE_METATYPE and without qRegisterMetaType: No warning, slot is called With Q_DECLARE_METATYPE and with qRegisterMetaType: No warning, slot is called. 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. QML_DECLARE_TYPE. 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++. 1. Actually, they are declared, but in a private section with the macro Q_DISABLE_COPY(). Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. To use the type T in queued signal and slot connections, qRegisterMetaType<T>() must be called before the first connection is established. If you are using queued connections, you need to register std::string as meta type. The fix is probably to include qsslsocket. D-Bus offers an extensible type system, based on a few primitive types and associations of them. 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. Qt Remote Objects Compiler. @kshegunov said: you're doing it wrong. In Qt, you can declare a variable in two ways: 1. The id is constexpr in the special case of Qt built-in types only. Declare new types with Q_DECLARE_METATYPE () to make them available. I however have a scenario where I want to declare such an object in qml and transmit it to the c++. 能猜到原因吗?注意看前面 Q_DECLARE_METATYPE() 代码, 对了。类中的成员函数qt_metatype_id中包含对qRegisterMetaType(typeName)的调用: 这儿就是辗转调用了这个带参数的qRegisterMetaType函数: unregisterType(const char *typeName) 函数的作用是取消自己先前注册的某个metatype类型。That is sad. c:55 This looks like some loader initialization mismatch, check debug vs release builds of your application and libraries. So in your case you need to declare. After googling this, I found this correspondence, which was only available through a third party archival site as google. Now you have a valid QObject. hi, I always after application running, receive debug text of: QObject::connect: Cannot queue arguments of type 'MyStruct'. Here you can see that the macro expands to nothing. So using qRegisterMetaType () you will just trade Q_ENUM () for Q_DECLARE_METATYPE (). Read and abide by the Qt Code of Conduct. After googling this, I found this correspondence, which was only available through a third party archival site as google. Any class or struct that has a public default constructor, a public copy constructor, and a public destructor can be registered. So in both cases qRegisterMetaType isn't required for the slot to be called and the custom type to be accessible within the slot (i. Q_GADGET makes a class member, staticMetaObject, available. Obviously, a call to qRegisterMetaType<T>(. Execute qRegisterMetaType<QItemSelection> (); before it is used as such, e. 1. Creating and Destroying Custom Objects 1 Answer Sorted by: 21 Objects are copied when put into a QVariant, but QObject derived classes cannot be copied, so the solution is to use a pointer to your class. I read on documentation that Q_DECLARE_METATYPE makes available type to QVariant, for example (I got it from documentation): @ struct MyStruct { int i;. Note: This function is thread-safe. It is not safe to make a QObject's copy constructor public. Here my test code and example:但是如何传递一个程序员自定义的结构体? 1)在定义结构体之后,要调用Q_DECLARE_METATYPE,向QT声明这个结构体 2)在main. your custom type definition. 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(). Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections. So I tried declaring the following at end of my worker thread class Q_DECLARE_METATYPE(cv::Mat);. This function was introduced in Qt 5. Accessing an enum stored in a QVariant. QtNetwork. 1 Answer. no unexpected garbage. Also Q_DECLARE_METATYPE does not register a type, but declares it. Read and abide by the Qt Code of Conduct. 1 Answer Sorted by: 21 Objects are copied when put into a QVariant, but QObject derived classes cannot be copied, so the solution is to use a pointer to your. The third without Q_DECLARE_METATYPE. 2. h in the translation unit where you have that line. qRegisterMetaType<FileNodePointer> ("FileNodePointer"); should be called once (in main, constructor etc. The file (called a "rep" file) uses a specific (text) syntax to describe the API. Jun 13, 2021 at 19:37. S 1 Reply Last reply Reply Quote 0. 0. I have added Q_DECLARE_METATYPE(quint32) in Class2. The "traditional" way of doing this is to convert each element to a QVariant, and pass collection as a QVariantList. Data Type Conversion Between QML and C++. // - in a header: // - define a specialization of this template calling an out-of. You can also use QMetaEnum::fromType() to get the QMetaEnum. Q_DECLARE_METATYPE. 总之,有时候,我们多么希望信号能发送自定义数据类型。. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. @Q_DECLARE_METATYPE (std::unique_ptr<Thing>);@. 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. Detailed Description The QMetaType class manages named types in the meta-object system. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. This results in access violations when Qt. In some cases in Qt 4, it is also necessary to use the qRegisterMetaType method. This function was introduced in Qt 6. Thus you need to use the runtime check QMetaType::type (). When the plugin is reloaded later, the old declaration still points to the original memory space of the now-unloaded library. qRegisterMetaType vs. Share Follow edited Apr 29, 2013 at 7:21 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. Obviously then you would not do registerComparator (). 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. x however, the code generated by moc will call qRegisterMetaType for you if moc can determine that the type may be registered as a meta-type. 0. Share Improve this answer Follow answered Jul 23, 2014 at 15:37. complains that the metatype isn't registered. Some structure need to be registered to be queued in asynchronous signals using qRegisterMetaType<T>(name), such as signal which passes QVector<int>. Enumerations that are declared with Q_ENUM have their QMetaEnum registered in the enclosing QMetaObject. The QML engine provides built-in support for a. "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. Note that you are technically lying to the meta type system. If you need the functionality provided by Q_DECLARE_METATYPE, you will have to use it. 用qRegisterMetaType对自定义的类型进行注册,就是为了告诉Qt如何去做这些事情。. and Q_DECLARE_METATYPE uses qRegisterMetaType() internally. Posted by Unknown at 2:06 AM. namespace CCS { Q_DECL_EXPORT Q_NAMESPACE. You can make them known ( Q_DECLARE_METATYPE ), however you can't register them as QML type. Well, I certainly overplayed this particular point, but the statement I believe is valid in principle. Good workaround: you may register your type with Q_DECLARE_METATYPE ( IBase * ) macro and wrap your. Also, to use type T with the QObject::property () API, qRegisterMetaType () must be. multithreaded software and I am getting the warning says: (Make sure 'QVector<int>' is registered using qRegisterMetaType (). wysota. To start viewing messages, select the forum that you want to visit from the selection below. From the docs: int qRegisterMetaType ( const char * typeName ) Registers the type name typeName to the type T. Then you should register your object to use it with QML. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections. But I can't see a method to insert myClass into. i. Current the only supported type info is QML_HAS_ATTACHED_PROPERTIES. See also disconnect(), sender(), qRegisterMetaType(), Q_DECLARE_METATYPE(), and Differences between String-Based and. Q_DECLARE_METATYPE (T) requires the type T to be default-constructable, copiable and destructable. c:55 This looks like some loader initialization mismatch, check debug vs release builds of your application and libraries. Detailed Description. Without this reference, it compiles just fine. The object it returns should also be a member of the factory class. The code compiles and runs ok. The documenation of this macro gives. waitForConnected ([msecs=30000]) # Parameters: msecs – int. This version of the function is to register alias types. uint64; If this is your first visit, be sure to check out the FAQ by clicking the link above. 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. To start viewing messages, select the forum that you want to visit from the selection below. The reasoning is found in the discussion on Identity vs Value on the Qt Object Model page. I tried to write one, but I failed. qRegisterMetaType vs. QAbstractSocket::SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType(). Any errors from Qt's metatype systems are usually due to MOC (the "meta-object compiler"), which reads your header files and generates a "moc" file with metatype information for every class where the Q_OBJECT macro is declared. qRegisterMetaType vs. To enable using the type in queued signals and such, there also needs to be a corresponding call: qRegisterMetaType<foo::FooState>(); Question. 基本理解. There's also no need for that typedef, it only makes the code less readable. But there would be no trouble using the QMetaType class or using qRegisterMetaType before creating an instance of QCoreApplication or QApplication. Call qRegisterMetaType() to make types available to non-template based functions, such as the queued signal and slot connections. So in your case you need to declare. By the way, Qt 4. qRegisterMetaType 必须使用该函数的两种情况. This is not the case, since the following succeeded: @QMetaType::type("MyClass"); // success@. Equivalent to Q_DECLARE_METATYPE(TYPE *) and Q_DECLARE_METATYPE(QQmlListProperty<TYPE>) QML_DECLARE_TYPEINFO (Type, Flags) Declares additional properties of the given Type as described by the specified Flags. e. 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. 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. As said in int qRegisterMetaType () documentation: To use the type T in QVariant, using Q_DECLARE_METATYPE () is sufficient. Declare new types with Q_DECLARE_METATYPE () to make them available. 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. 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. This is by design. In short, I get following error: QObject::connect: Cannot queue arguments of type 'cv::Mat' (Make sure 'cv::Mat' is registered using qRegisterMetaType (). Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. To copy to clipboard, switch view to plain text mode. But with the shared_ptr object, not a pointer to the shared pointer! You will have to register std::shared_ptr<yourclass> with the Qt meta object system before this can work, i. [edit] forgot to mention that you also have to use a worker object. This won't work because you can't use qMetaTypeId<> () before Q_DECLARE_METATYPE<>. 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. I'm trying to use custom classes in QAbstractListModel, and the Q_DECLARE_METATYPE doesn't work at all! To test where the problem is, I've simplified the code as the following: #include <QMetaType> #include <QVariant> #include <QDebug> typedef int x; Q_DECLARE_METATYPE (x) void main () { QVariant v; qDebug () << v. [quote author="Andre" date="1306394817"]In that case, I think you need to register them. uint64; If this is your first visit, be sure to check out the FAQ by clicking the link above. QVariant v = QVariant::fromValue<cMyClass>(MyObject); However, as soon as I use Q_DECLARE_METATYPE, I get errors about using a deleted function. 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. It does not say anything about registering the type. h) of the derived class. goocreations 12 Mar 2013, 07:22. You may have to register before you can post: click the register link above to proceed. You don't pass around copies of QObject derived types because it is not copyable. QList<T> isn't really a pre-defined variant type (except QList<QVariant>) so it technically resolves to a QMetaType::UserType. Even though we do not intend. See the Qt D-Bus Type System page for more information on the type system. 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(). g. Using Q_ENUM () allows you to retrieve at run-time the name of an enum value: Q_GADGET makes a class member, staticMetaObject, available. SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType(). It associates a type name to a type so that it can be created and destructed dynamically at run-time. If the pointer stored in the QVariant can be qobject_cast to T, then that result is returned. 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. It's not enough to get reflection features out of a type this way (it does not create a QMetaObject), so for the thing to be useful at all you need at least Q_GADGET in both base and derived classes. Qt Base (Core, Gui, Widgets, Network,. Update. 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(). 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. 1. You should use qmlRegisterType function for that. class Test : public QWidget { Q_OBJECT public: Test(); signals: public slots: void setAppData(QList<QIcon> icons, QStringList names, QStringList versions, QStringList publishers, QString installLocation, QStringList uninstallLocations); private: }; Q_DECLARE_METATYPE(QIcon) The same issue is still present. The struct is declared in my worker class, which is inside a namespace. Re: How to use Q_DECLARE_METATYPE. Returns the internal ID used by QMetaType. ) which are updated by simulation code. To use the type T in QVariant, using Q_DECLARE_METATYPE() is sufficient. 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. So my first idea:. 2. Q_DECLARE_METATYPE (std::string) Quoting Qt Doc. See also isRegistered () and Q_DECLARE_METATYPE (). Q_DECLARE_METATYPE only registers a type in meta type system. rep file extension, short for Replica. The other overload around has almost the same form but for the fact that it. Registers the type name . To use the type T in queued signal and slot connections, qRegisterMetaType () must be called before the first connection is established. This macro is used to specialise the template class QMetaTypeId with typename TYPE, in which, a static member function qt_metatype_id () is defined. [virtual] QLocalSocket:: ~QLocalSocket Destroys the socket, closing the connection if necessary. @Q_DECLARE_METATYPE (std::unique_ptr<Thing>);@. This function returns the Qt meta type id for the type (the same value that is returned from qRegisterMetaType()). In the example's Message class, a static method is included to do this. Call qRegisterMetaType () to make types available to non-template based functions, such as the queued signal and slot connections. 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. Sorted by: 5. h" class Context : public QObject { Q_OBJECT Q_PROPERTY (MyGadget* gadget READ gadget CONSTANT) public: explicit Context () : QObject {nullptr} { } MyGadget* gadget () { return &_gadget; } private. I only care about runtime instantiation. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. " –If I declare Class B as follows, it works fine, despite the fact that I haven't done Q_DECLARE_METATYPE for the pointer: #include <QObject> #include <QMetaType> #include "a. The default access for a class is private, so that Container* data(); declares a private member function, but it looks like you expect it to be public. To achieve this you need Q_DECLARE_METATYPE macro and qRegisterMetaType () function. qRegisterMetaType usage. Any class or struct that has a public default constructor, a public copy. You may have to register before you can post: click the register link above to proceed. This function was introduced in Qt 4. It associates a type name to a type so that it can be created and destructed dynamically at run-time. Add qRegisterMetaType and qDBusRegisterMetaType calls to enable the framework to work with the custom type. QAbstractSocket::SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType(). See also state() and Creating Custom Qt Types. I have a problem with a class that exchanges data using TCP/IP socket. That said, your stack trace is really strange: _dl_debug_initialize (ldbase=4294967292, ns=1095236752) at dl-debug. Note that you are technically lying to the meta type system. You should use Q_DECLARE_METATYPE macro for this. 8. Declare new types with Q_DECLARE_METATYPE() to make them available to QVariant and other template-based functions. More. It will return the same result if it was called before. Jul 9, 2017 at 21:51. In that case, I think you need to register them. To start viewing messages, select the forum that you want to visit from the selection below. Franzk 26 May 2011, 06:59. Basically, I created a library containing a type: struct MyCustomType {. Q_DECLARE_METATYPE, as pointed out by @SingerOfTheFall, would register template based type into QVariant (so it can be retrieved using qvariant_cast<T>()). +50. QVariant::fromValue () returns a QVariant. Also, to use type T with the QObject::property () API,. 1. Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. The logical equivalent of a const T &r (reference to const T) is a const T * const p (const pointer to const T). Q_DECLARE_METATYPE(MyObject*) somewhere in your code. It would look something like this: Q_DECLARE_METATYPE (MyNamespace::MyClass::MyEnum) However, the Q_DECLARE_METATYPE macro would expand to the following call to qRegisterMetaType: qRegisterMetaType< MyNamespace::MyClass::MyEnum > ("MyNamespace::MyClass::MyEnum",. Using the Q_DECLARE_METATYPE () macro 2. Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. 3 Answers Sorted by: 13 "qRegisterMetaType" is a function. 3 to Qt4. That said, your stack trace is really strange: _dl_debug_initialize (ldbase=4294967292, ns=1095236752) at dl-debug. @kshegunov said in Undocumented automatic metatype registration in Qt6?: Your original code (in the top-mentioned topic) assumes std::unique_ptr is copyable, which it isn't, so it can not ever be a metatype. The Q_DECLARE_METATYPE() macro and qRegisterMetaType() function documentation contain more detailed information about their uses and limitations. G. JulienMaille @kshegunov last edited by JulienMaille . 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. 2 Answers. Step 1 (mark for MOC), build some QObjects That pattern uses Q_PROPERTY and Q_OBJECT and the MoC tool. qRegisterMetaType vs. Declare new types with Q_DECLARE_METATYPE () to make them available. QMetaType Synopsis Functions def __eq__ (b). in a header file and call @qRegisterMetaType<std::unique_ptr<Thing>> ();@ before your signal and slots are used. 4 and it seems to work. // This primary template calls the -Implementation, like all other specialisations should. 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. I'm using Qt 5. Declare new types with Q_DECLARE_METATYPE() to make them available to QVariant and other template-based functions. uint64; If this is your first visit, be sure to check out the FAQ by clicking the link above. I am also using some in queued signal and slot connections. This worked very well. Hope it. Additional types can be registered using qRegisterMetaType() or by calling registerType(). 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. QLocalSocket::SocketState is not a registered metatype, so for queued connections, you will have to register it with Q_DECLARE_METATYPE() and qRegisterMetaType(). 手册中告诉我们,执行这个的时候,模板参数T必须用 Q_DECLARE_METATYPE() 声明过 能猜到原因吗?注意看前面 Q_DECLARE_METATYPE() 代码, 对了。类中的成员函数qt_metatype_id中包含对qRegisterMetaType(typeName)的调用 这儿就是辗转调用了这个带参数. 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. Any idea what I'm missing please? BTW, no problem at all using Schedule in QMetaProperty or QVariant. Declare new types with Q_DECLARE_METATYPE () to make them available to QVariant and other template. Q_DECLARE_METATYPE(Pkg) and this does not give compile errors, but in my main. This results in access violations. Passing across threads (queued connection) will copy the QVector in either case, but the const will remind you that you cannot alter the original QVector in. Normally, you would only register the pointer form if your class cannot be copied, as in the case of QObject and derivatives, but. So, you don't want 'Widget' to be a metatype, you want 'Widget*' to be a metatype so that you can put a Widget* in a QVariant for example. cpp. Also, this Q_DECLARE_METATYPE(SharedTestClass) shouldn't be needed. 1.