[PyQt] Problem with pyqt (python 2.6)

Nick Gaens mail at nickgaens.com
Thu May 6 11:25:18 BST 2010


On Thu, May 6, 2010 at 12:14 PM, rosso rossi <emilio84music at yahoo.it> wrote:

> Hello everybody,
>
> I'm writing a small interface with python 2.6.5 and pyqt 4.7.3.
>
> I'm testing this interface on windows, but i have the same problem in linux
> (windows and linux are 32-bit OS).
>
> So... This is my problem:
>
> In my interface i have 1 qpushbutton (self.Button) and 2 QLineEdit (Edit1,
> and edit2)
>
> i connected qpushbutton with a funzion (pressbutton)
>
> def pressbutton(self):
>      self.thread = threading.Thread( target=self.Thcall )
>      self.thread.start()
>
> def Thcall(self):
>         while(True):
>             self.t = Timer(10, self.Read) #10 seconds
>             self.t.start()
>             self.t.join()
>
> def Read(self):
>         Edit1.setText("a string")
>         Edit2.setText("another string")
>         #now here i have 500 linees of code, i read from serial port and
> compute these datas. It's take about 500ms
>         Edit1.setText("finished")
>         Edit2.setText("finished")
>
>
>
> as you can see my program is very simple (i omitted the first part, where i
> initialize Qwidget and move them in my window). But when my program enter in
> self.Read my windows freeze for some time (< 1 second). This is the first
> problem. Why it freeze?
>


So, you omit 500 rules of code in which you listen to a serial port and need
500 milliseconds to calculate the received data.. My guess is that somewhere
in those 500 lines of code, you call a method that's blocking the event loop
of Qt. Probably a serialPort.read() invocation or so.. There is a way out
though: you might want to look at QThread instead of using the python
threading module. I'm not sure, but it doesn't secure the flow of the main
event loop where QThread does so.



> Second problem: If i switch from antoher program (for example firefox) and
> my program, this crash....
>
> Is there some error in my code?
>

Well, I can say this isn't the fault of Firefox, nor python or PyQt. Maybe
the cause can be found in the serial port listener? Again, you've omitted
that part, so nobody can say for sure.

>
> i want that when user push a button, my program will call function Read
> every 10 seconds FOREVER....
>
> Thank you very much and sorry for my bad english
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>

-- 
Nick Gaens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100506/d101c464/attachment.html>


More information about the PyQt mailing list