使用std :: string失败信号和插槽 [英] Using std::string fails Signals and Slots
问题描述
我的信号和槽都有一个 std :: string
类型参数。我的信号是在类b和插槽在类A.如果我将参数类型更改为int该信号工作,但失败与std :: string.Any如何解决这个问题的建议?
Both of my signal and slots have a std::string
type parameter. My signal is in class b and slot in class A. If i change the parameter type to int the signal works but fails with a std::string.Any suggestions on how I could resolve this issue ?
这里是我使用的代码
connect(this,SIGNAL(SignalB(std::string)),ClassA::PtrClassA,SLOT(MethodA(std::string)));
推荐答案
如果使用排队连接, std :: string
作为元类型。在其中一个标头中使用 Q_DECLARE_METATYPE(std :: string)
。
If you are using queued connections, you need to register std::string
as meta type. Use Q_DECLARE_METATYPE(std::string)
in one of your headers. Call qRegisterMetaType<std::string>();
in the initialization of your code.
See QMetaType docs for more information.
这篇关于使用std :: string失败信号和插槽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!