Pergunta

Alguém poderia me dar um exemplo de como configurar o QSocketNotifier para disparar um evento se algo acontecer /dev/ttys0 ? (de preferência em python/pyqt4)

Foi útil?

Solução

Aqui está um exemplo que apenas continua lendo um arquivo usando QSocketNotifier. Basta substituir esse 'foo.txt' por '/dev/ttys0' e você deve estar pronto.


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_()

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top