有人可以给我一个示例,说明如何设置qsocketNotifier如果有什么事 /dev/ttys0 ? (最好在Python/Pyqt4中)

有帮助吗?

解决方案

这是一个示例,只需使用qsocketNotifier从文件中读取。只需用“/dev/ttys0”替换该“ foo.txt”,就应该很好。


import os

from PyQt4.QtCore import QCoreApplication, QSocketNotifier, SIGNAL


def readAllData(fd):
        bufferSize = 1024
        while True:
                data = os.read(fd, bufferSize)
                if not data:
                        break
                print 'data read:'
                print repr(data)


a = QCoreApplication([])

fd = os.open('foo.txt', os.O_RDONLY)
notifier = QSocketNotifier(fd, QSocketNotifier.Read)
a.connect(notifier, SIGNAL('activated(int)'), readAllData)

a.exec_()

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top