emit std::string with qt signal

2020-02-05 13:51发布

问题:

I am trying to emit standard string with qt signal. The signal will be delivered as queued. I registered the type with qRegisterMetaType , like it says in the qt documentation, but no luck. I am registering it like this qRegisterMetaType<std::string>("std::string")

回答1:

You should also do:

Q_DECLARE_METATYPE (std::string)

Quoting Qt Doc

Adding a Q_DECLARE_METATYPE() makes the type known to all template based functions, including QVariant. 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.



标签: c++ qt qt4