Hi,

Attached is a simple testcase which emits a signal from a worker thread, and 
then waits until the main thread has released a database connection.

It works fine under Linux, but under OSX Qt 4.7RC, PyQt 4.7.4, the slot never 
get's called, i.e. print "slot called" never gets executed.

From Googling around I know that putting the main thread to sleep with a 
QWaitCondition also puts the event loop to sleep. However, here we don't put 
the main thread to sleep, but only the worker thread, and only after we emit 
the signal.

What then is the reason that the slot never gets called on OSX?

Cheers,

Peter
import os
import sys
import select
import socket

from PyQt4 import QtCore, QtGui

mutex = QtCore.QMutex()
database_released = QtCore.QWaitCondition()


class ServerThread(QtCore.QThread):

    sync_started_signal = QtCore.pyqtSignal()
    
    def __init__(self):
        QtCore.QThread.__init__(self)
        self.server_has_connection = False

    def run(self):
        mutex.lock()
        print "emitting signal..."
        self.sync_started_signal.emit()
        print "waiting for main thread..."
        if not self.server_has_connection:
            database_released.wait(mutex)
        print "OK!"
        mutex.unlock()
          
class QtSyncServer(QtCore.QObject):

    def __init__(self):
        self.thread = ServerThread()
        self.thread.sync_started_signal.connect(\
                self.unload_database)
        self.thread.start()

    def unload_database(self):
        print "slot called"
        mutex.lock()
        if not self.thread.server_has_connection:
            self.thread.server_has_connection = True
            database_released.wakeAll()
        mutex.unlock()        

app = QtGui.QApplication(sys.argv)

widget = QtGui.QWidget()
widget.resize(250, 150)
widget.setWindowTitle('simple')
widget.show()

q = QtSyncServer()

app.exec_()
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to