[PyKDE] PyQt Qthreads

Gregor Kling gregor.kling at dvz.fh-giessen.de
Tue Oct 31 11:29:19 GMT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hello,

Maybe there has someone an idea what is wrong with my (possibly
braindead) interaction with a database query and the representation in a
Dialog.

I have a class Finder with following impl:
class Finder(QtCore.QThread):
    def __init__(self,search_for):
      QtCore.QThread.__init__(self,None)
      try:
        self.__dbcon = DVZdbCon().get_con()
        self.resultQueue = Queue.Queue()
        self.len = 0
        self.search_for = search_for
      except MySQLdb.Error,e:
        raise

    def get_next_data(self):
      if(self.len > 0):
        self.len -= 1
        return self.resultQueue.get(block=False)
      else:
        raise Queue.Empty

    def run(self):
      query = <select stmt>
      try:
        cursor = self.__dbcon.cursor()
        cursor.execute(query,('%%%s%%' % self.search_for))
        result = cursor.fetchall()
        self.len = len(result)
        try:
          for row in result:
            host_id = row[0]
            host = hostData(self.__dbcon) # a container class
            host.fill_host_by_host_id(host_id)
            self.resultQueue.put(host)
        except DVZvalueError,e: # local Exception class
          raise
      except MySQLdb.Error,e:
        raise
      return

and a Gui env, with following part of the class:
..
self.finder = Finder(<search text 4 query>)
self.finder.start()
...
 try:
      while(1):
        host = self.finder.get_next_data()
        nk = host.get_name_ipv4()[0]
        host_id = nk.get_name()
        print host_id # does well
        tw.insertRow(row) # table widget
        domain = host.get_domain_ipv4()
        dname = domain.get_domain_name()
        ti = QtGui.QTableWidgetItem()
        ti.setText(str(host_id))
        tw.setItem(row,0,ti)
        ti = QtGui.QTableWidgetItem()
        ti.setText(str(dname))
        tw.setItem(row,1,ti)
        row += 1
    except Empty,e:
      pass

I think these parts are enough..
So here my question and observation.
First. Can I really use the Queue to synchronize data from within the
Qthread env ?

I can see that the printouts are as intended, but
the presentation in the WidgetTable ist presented when
the thread is complete instead of an iterative update.


Anyone has an idea ?



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFFRzOPJFHWQ694uCYRAs5JAJ9ysK4XqprlltmvUeNaquudUue4/gCfZpwt
p/vqnWr9/g5HBxpe+h49Zyw=
=UV+k
-----END PGP SIGNATURE-----




More information about the PyQt mailing list