Hi Horst
On Sat, Aug 13, 2011 at 1:32 PM, Horst Düster <[email protected]> wrote:
> Hi
>
> I'm playing with use of PyQt QThreads in a plugin. But I'm not successful. I
> created a very simple plugin with the aim to understand the threading
> mechanisms of PyQt. The GUI collects number of iterations and the thread
> does nothing else than to iterate over this number. When I start the
> iteration process sometimes it works, but very slow.
What happens if it does not work? And how would you quantify the slowness?
> Sometimes the result
> will appear after closing and reopening the GUI.
This could be caused by the buffering mechanisms on standart output.
Maybe you will have more luck using standart error stream (stderr)
which should not be buffered - or by flushing the stream.
> I'm a little bit confused
> about these results. I appended the plugin. Maybe someone outside is able to
> help. I would appreciate an hint or help.
I have modified the code a bit so that I could run it without QGIS.
Everything worked as expected. I have attached the modified dialog
file - check out whether it will work better when run from outside
QGIS.
Martin
# -*- coding: iso-8859-1 -*-
"""
Module implementing ThreadsDialog.
"""
from PyQt4.QtGui import *
from PyQt4.QtCore import *
from Ui_Threads import Ui_Ui_Threads
import time
import sys
class ThreadsDialog(QDialog, Ui_Ui_Threads):
"""
Class documentation goes here.
"""
def __init__(self, parent = None):
"""
Constructor
"""
QDialog.__init__(self, parent)
self.setupUi(self)
def result(self, message):
self.btnOK.setEnabled(True)
QMessageBox.information(None, '', message)
@pyqtSignature("")
def on_btnOK_clicked(self):
self.btnOK.setEnabled(False)
self.theThread = MyThread(self.spinBox.value(), self.parent())
self.connect(self.theThread, SIGNAL("serviceFinished(QString)"), self.result)
self.theThread.start()
class MyThread(QThread):
def __init__(self, maxIt, parent = None):
QThread.__init__(self, parent)
self.maxIt = maxIt
print "created"
def run(self):
print "started", self.maxIt
for i in range(self.maxIt):
print i
self.emit(SIGNAL("serviceFinished(QString)"), 'Thread finished after '+str(i)+' iterations. Finished: ')
pass
a = QApplication(sys.argv)
dlg = ThreadsDialog()
dlg.show()
a.exec_()
_______________________________________________
Qgis-developer mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-developer