I still have had no luck getting this to work. In all examples I can find, the only part of the object that runs in a thread is a single method, not other parts of the class. For example in the code from SO:

Qt Code:
  1. from PySide import QtCore
  2. import time
  3. import sys
  4.  
  5.  
  6. # Subclassing QObject and using moveToThread
  7. # http://labs.qt.nokia.com/2007/07/05/qthreads-no-longer-abstract/
  8. class SomeObject(QtCore.QObject):
  9.  
  10. finished = QtCore.Signal()
  11.  
  12. def longRunning(self):
  13. count = 0
  14. while count < 5:
  15. time.sleep(1)
  16. print "Increasing"
  17. count += 1
  18. self.finished.emit()
  19.  
  20.  
  21.  
  22.  
  23.  
  24.  
  25. def usingMoveToThread():
  26. app = QtCore.QCoreApplication([])
  27. objThread = QtCore.QThread()
  28. obj = SomeObject()
  29. obj.moveToThread(objThread)
  30. obj.finished.connect(objThread.quit)
  31. objThread.started.connect(obj.longRunning)
  32. objThread.finished.connect(app.exit)
  33. objThread.start()
  34. sys.exit(app.exec_())
  35.  
  36.  
  37.  
  38. if __name__ == "__main__":
  39.  
  40. usingMoveToThread()
To copy to clipboard, switch view to plain text mode 

This is really only calling the "longrunning" method in another thread, and other operations that I could call on the class would seem to be required to call "start" on the class again and make another instance, then call another method in a separate thread which for the database would mean calling the constructor again and reconnecting to the database again. I don't mind if database operations get queued in the worker thread, actually that would be preferable because the throughput to a single DB is not going to increase be trying to connect twice anyway. I just want to use the DB instance with values it returns going to the GUI when it is done pulling the data (without freezing the GUI during the network operations). Because I already had the class/object set up correctly to work I thought it would make sense to do it this way but maybe what I am saying is impossible. Here is an example of what I am looking for:

Suppose I have this class (hastily written so it might not be completely perfect):
Qt Code:
  1. class DBcore(QtCore.QObject):
  2.  
  3.  
  4. def __init__(self, parent=None):
  5. super(DBcore, self).__init__(parent)
  6. connection = pymongo.MongoClient(connection_string)
  7. database = connection.avdb
  8. self.db = database
  9.  
  10.  
  11.  
  12. def showDatabaseTable(self, tableToLoad):
  13.  
  14. for q, row in enumerate(self.requests.find()):
  15. table_rows += 1
  16. if q == 0:
  17. for col in row:
  18. table_cols += 1
  19. time.sleep(0)
  20. else:
  21. pass
  22.  
  23. self.retr_table_cols = table_cols
  24. self.retr_table_rows = table_rows
  25. self.retr_data = self.requests.find().sort([('_id',1)])
  26.  
  27.  
  28. return (self.retr_table_cols, self.retr_table_rows, self.retr_data)
To copy to clipboard, switch view to plain text mode 

In my GUI object or somewhere in a higher level, I would put "DB = DBcore()" and then either use the functions like DB.showDatabaseTable(clients) or just use mongoDB in a random write or something like DB.db.clients.insert({"name":"John"}). In both of these cases I would like the operation to run in a separate thread automatically, because it is using the "DB" object. Is this possible or unheard of?

Thanks.