We won't know unless you implement the thread. The thread needs to emit a signal that will update the progress bar. I don't see that in your code.
We won't know unless you implement the thread. The thread needs to emit a signal that will update the progress bar. I don't see that in your code.
You can use custom events but using signals is simpler. They use the event mechanism behind the scenes, so the result is the same, just less coding.
Ok the...I try to make it your way and i post the revised code below. I get the same error message as before: "TypeError: 'int' object is not callable" at t.start() line.
here is the code:
Qt Code:
import sys from PyQt4 import QtCore, QtGui from calculatorform_ui import Ui_CalculatorForm from ui_countNumbers import Ui_MainWindow from time import sleep def __init__(self, form, start, end): self.start = start self.end = end self.form = form def run(self): c = C() for x in range(start, end): c.emit(c.update, x) update = QtCore.SIGNAL("update(int)") def __init__(self, parent=None): self.ui = Ui_MainWindow() self.ui.setupUi(self) @QtCore.pyqtSignature("") def on_start_clicked(self): t = WorkerThread(self, self.ui.spFrom.value(), self.ui.spTo.value() + 1); t.start()To copy to clipboard, switch view to plain text mode
I am very much frustrated here...
Software Engineer, riding a Kona King Kikapu 2007
After a lot of study, i now coded it more correctly (i think) but strangely enough i get the same error message as before. ('int' object is not callable" at t.start() )
Code is:
Qt Code:
import sys from PyQt4 import QtCore, QtGui from calculatorform_ui import Ui_CalculatorForm from ui_countNumbers import Ui_MainWindow from time import sleep def __init__(self, start, end): self.start = start self.end = end def run(self): for x in range(start, end): self.emit(QtCore.SIGNAL("updateProgress"), x) def __init__(self, parent=None): self.ui = Ui_MainWindow() self.ui.setupUi(self) @QtCore.pyqtSignature("") def on_start_clicked(self): worker = WorkerThread(self.ui.spFrom.value(), self.ui.spTo.value() + 1); QtCore.QObject.connect(worker, QtCore.SIGNAL("updateProgress"), self.updateProgress, QtCore.Qt.QueuedConnection) worker.start() def updateProgress(self, val): self.ui.progres.setValue(val) if __name__ == "__main__": count = CountNumbersForm(); count.show() sys.exit(app.exec_())To copy to clipboard, switch view to plain text mode
Software Engineer, riding a Kona King Kikapu 2007
What is class C?
I can give you a draft of C++ code that does what you want. Then you can translate it into python, as my python skills are a bit stale...
Of course there are other ways to do the same thing, for example the propagate() signal is not needed, you can connect the original signal directly to the progress bar if you have access to it.Qt Code:
Q_OBJECT public: void emitSignal(int v){ emit sig(v); } signals: void sig(int); }; Q_OBJECT public: void run() { Emiter e; connect(&e, SIGNAL(sig(int)), this, SIGNAL(propagate(int))); i=0; while(i<=100){ sleep(1); e.emitSignal(i++); } } signals: void propagate(int); }; //... MyThread thread; QProgressBar pbar; connect(&thread, SIGNAL(propagate(int)), &pbar, SLOT(setValue(int))); thread.start();To copy to clipboard, switch view to plain text mode
Software Engineer, riding a Kona King Kikapu 2007
The code you posted is dangerous because you emit a signal from a worker thread on account of an object that is in the gui thread and I have no idea in context of which thread the signal will be emitted and will it be queued or executed directly. My Emiter class makes sure the context of the worker thread is used and the signal is queued and propagated in the context of the GUI thread.
But isn't the whole idea ?? In C# we use delegates to do that, in Qt i hoped that with Signals and Slots i will be able to do it. I think that Qt automatically find the correct thread to "use".
Your Emiter class is "translated" to Python like this ?
Qt Code:
def __init__(self): def emitSignal(self, val): self.emit(QtCore.SIGNAL("updateProgress"), x)To copy to clipboard, switch view to plain text mode
And what is the purpose (and implementation as it is not shown how it does it's work) of MyThread:: propagate ? Just to forward the signal ?
I think i am stuck...
Last edited by kikapu; 22nd May 2007 at 15:35.
Software Engineer, riding a Kona King Kikapu 2007
Yes, but I'm not sure what it will decide when you call a function from an object that lives in another thread. It might work, but I'm not sure, therefore I used this kind of "proxy".
Looks correct.Your Emiter class is "translated" to Python like this ?
Qt Code:
def __init__(self): def emitSignal(self, val): self.emit(QtCore.SIGNAL("updateProgress"), x)To copy to clipboard, switch view to plain text mode
Yes, just to forward the signal. As I mentioned, you could do it without it, but then you'd have to have access to the progress bar from within the thread object. That's your choice.And what is the purpose (and implementation as it is not shown how it does it's work) of MyThread:: propagate ? Just to forward the signal ?
Yes, i now what you mean, we sometimes use it in .net too. But i am afraid i can not go too far, every solution that i implement, i see this error "TypeError: 'int' object is not callable"
I really feel like an idiot, i have written countless thousands lines of code in my life and i am stucked in 10 lines of this. What can i say...![]()
Software Engineer, riding a Kona King Kikapu 2007
Are you sure this is correct?
You have a variable called start and then you call start as a method. Try using a different name here. Maybe that's the problem.Qt Code:
def __init__(self, start, end): self.start = start self.end = endTo copy to clipboard, switch view to plain text mode
kikapu (22nd May 2007)
Software Engineer, riding a Kona King Kikapu 2007
Bookmarks