在Qt中有什么快速触发信号槽的好方法吗?
Is there any good way to quickly trigger a signal slot in Qt?
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。
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。