开发者

Qt.QueuedConnection never sends message

Why does this program not print anything?

from PyQt4.QtCore import *
from PyQt4.QtGui import *

class A(QObject):
    def __init__(self):
        super(A, self).__init__()

    sig = pyqtSignal()

    @pyqtSlot()
    def slot(self):
        print("received")

a = A()
a.sig.connect(a.slot, Qt.QueuedConnection)

a.sig.emit()
a.si开发者_开发百科g.emit()
a.sig.emit()

If I remove Qt.QueuedConnection, it works as expected. I'm trying to see if Qt.QueuedConnection will automatically remove duplicate events.


I'm not an expert with Python (or PyQt), but a queued connection only get's delivered once the application enters the event loop again, whereas a normal connection corresponds to a direct function call. So I guess in your case you have to wait until the application enters the event loop for the slot to be called (although I don't see any application object in your code).

EDIT: And I doubt that it removes duplicate calls, as Qt doesn't know if it's a duplicate call or a conceptually different call that should be carried out additionally.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜