c++ - 发出带有 qt 信号的 std::string

标签 c++ qt qt4

我正在尝试使用 qt 信号发出标准字符串。信号将按队列传递。我用 qRegisterMetaType 注册了类型,就像它在 qt 文档中所说的那样,但没有运气。我是这样注册的 qRegisterMetaType<std::string>("std::string")

最佳答案

你也应该这样做:

Q_DECLARE_METATYPE (std::string)

引用 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 信号的 std::string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7698986/

相关文章:

c++ - 构造/破坏 QApplication 导致 QWebView 搞乱 HTML 的呈现

c++ - 使用Direct2D绘制样条线

c++ - 将指向 QML 字符串属性的指针传递给 C++

c++ - 如果模板 arg 是 const,则将 const 添加到类型

c++ - Qt 工具栏/qtoolbutton 操作从未​​触发

linux - 为 arm 交叉编译 Qt 的 OpenGL 模块

c++ - QPainter 和 QOpenGLWidget 类中的 OpenGL native 代码

c++ - 如何读取包含多个根元素的 JSON 文件?

c++ - 将 "a set strings"和 "input from QLineEdit"连接成一个 QString

c++ - 使用 on_<widget>_<signal> where widget it own class