c++ - 在Qt中有什么快速触发信号槽的好方法吗?

标签 c++ qt signals-slots

Qt中多线程使用'emit'发送大量信号,触发很慢。貌似有排队机制。有没有什么好的方法可以快速触发线上的一个信号槽?

最佳答案

你问的是Qt::DirectConnection。您需要在 connect() 中指定它以保证插槽将立即被调用。

使用时:

The slot is invoked immediately when the signal is emitted. The slot is executed in the signalling thread.

否则,默认的 Qt 方式称为 Qt::AutoConnection

If the receiver lives in the thread that emits the signal, Qt::DirectConnection is used. Otherwise, Qt::QueuedConnection is used. The connection type is determined when the signal is emitted.

您可以在 connect() 中指定连接类型:

QMetaObject::Connection QObject::connect(const QObject *sender, const    
   char *signal, const QObject *receiver, const char *method,    
   Qt::ConnectionType type = Qt::AutoConnection)

关于这两者之间的区别以及如何使用的很好的答案是 here .

关于c++ - 在Qt中有什么快速触发信号槽的好方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40275711/

相关文章:

qt - QListView 的 Esc 键按下事件

c++ - 从 std::map 派生的类不能在 Visual C++ 上编译(但可以在 gcc 和 clang 上编译)

c++ - 编写可插件应用程序的最佳方法是什么?

c++ - 在设置值之前是否必须调用 promise.get_future() ?

c++ - 暴露所包含小部件的信号/插槽的正确 Qt 习惯用法是什么?

c++ - 保持 GUI 独立

c++ - 在声明时将静态二维数组初始化为零

c++ - 在将几行 ruby​​ 代码转换为 C++ 时需要帮助!

c++ - QX11EmbedContainer 和 QProcess 问题

java - 如何使用 Mongodb C++ 避免重复