Can I use a template type in any way as a slot or signal argument? As an example, I'm trying to define the following:
void exampleSignal(std::map<non_template_type_1,non_template_type_2> arg);
void exampleSlot(std::map<non_template_type_1,non_template_type_2> arg);
This results in the following during runtime:
QObject::connect: Cannot queue arguments of type
'std::map<non_template_type_1,non_template_type_2>'
(Make sure 'std::map<non_template_type_1,non_template_type_2>'
is registered using 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.
As a workaround, I'm using QVariantMap
instead of std::map
. But I really would like to know the correct way to solve this problem; one where it is not possible to modify the template classes.
Edit: I forgot to mention that the signal and slot are emitted and received in different threads. Apparently the runtime error doesn't occur in single-thread scenarios.