The answer is:<br>Just read carefully about QEvent and QCoreApplication.postEvent and you&#39;ve know that there is no need to use QWaitCondition at all in this case.<br><br><div class="gmail_quote">On Tue, Dec 1, 2009 at 10:15 PM, Ruslan Popov <span dir="ltr">&lt;<a href="mailto:ruslan.popov@gmail.com">ruslan.popov@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi, all.<br><br>I am working on a part of application, the app needs to read RFID id from label, RFID reader is accessible via COM port (I&#39;ve used pyserial for that).<br>
<br>I have tried to do so:<br><br>[main code]<br>
class MainWindow(QMainWindow):<br><br>    def __init__(self, parent=None):<br>        QMainWindow.__init__(self, parent)<br><br>        self.rfidReader = QWaitCondition()<br>        self.rfidWaiter = QWaitCondition()<br>
        self.rfidMutex = QMutex()<br>
        self.callback = self.readedRFID<br>        self.reader = WaitingRFID(self)<br>        self.reader.start()<br><br>..<br><br>    def waitingRFID(self):<br>        self.rfidReader.wakeAll()<br><br>        self.dlg = DlgWaitingRFID()<br>

        self.dlg.setModal(True)<br>        self.dlg.exec_()<br><br>        #self.rfidMutex.lock()<br>        #self.rfidWaiter.wait(self.rfidMutex)<br>        #self.rfidMutex.unlock()<br><br>    def readedRFID(self, rfid):<br>

        self.rfid_id = rfid<br>        print &#39;readedRFID:&#39;, rfid<br>        #self.rfidWaiter.wakeAll()<br>        self.dlg.close()<br><br>[Thread code]<br>class WaitingRFID(QThread):<br>    def __init__(self, parent):<br>

        self.callback = parent.callback<br>        self.mutex = parent.rfidMutex<br>        self.condition = parent.rfidReader<br>        QThread.__init__(self)<br><br>    def hex(self, symbol):<br>        return &#39;%02X&#39; % ord(symbol)<br>

<br>    def run(self):<br>        while True:<br>            port = serial.Serial(PORT[&#39;name&#39;], PORT[&#39;rate&#39;],<br>                                 bytesize = PORT[&#39;bits_in_byte&#39;],<br>                                 parity = PORT[&#39;parity&#39;],<br>

                                 stopbits = PORT[&#39;stop_bits&#39;]<br>                                 )<br>            port.setDTR(True)<br>            port.setRTS(True)<br><br>            self.mutex.lock()<br>            self.condition.wait(self.mutex)<br>

<br>            buffer = []<br>            while True:<br>                symbol = port.read(1)<br>                if not self.hex(symbol) == &#39;0D&#39;:<br>                    buffer.append(symbol)<br>                else:<br>

                    if &#39;0A&#39; == self.hex(port.read(1)):<br>                        if len(buffer) == 9:<br>                            rfid_code = &#39;&#39;.join(buffer[1:]) # see manager.py<br>                            break<br>

                        buffer = []<br><br>            self.callback(rfid_code)<br>            self.mutex.unlock()<br><br>            port.close()<br><br>Thread code works well. The problem is in showing dialog.<br>I need to show dialog with a label &#39;Put RFID label on the reader.&#39; and run thread&#39;s loop. The loop reads RFID id and use callback function. At this point I need to close the dialog window. Tell me the right way to do it.<br>

<br>Any help appreciated,<br clear="all"><font color="#888888">-- <br>Ruslan Popov<br>phone: +7 916 926 1205<br><br>
</font></blockquote></div><br><br clear="all"><br>-- <br>Ruslan Popov<br>phone: +7 916 926 1205<br><br>