473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

threading, qt, and the freakout

Hey everyone,

Why doesn't this work? The code speaks much more clearly than I do,
so i shortened it and pasted it below. Running this
and clicking on 'Break Me' will... freak out the window...

But... only when the pushbutton_obj.setText("Updated") line
is in the thread. If I comment out the threading code
and uncomment the line below "#WORKS", the button text
updates fine. But in the thread it breaks...

I feel like I'm being stupid here, so ANY suggestions are
much appreciated.

Thanks all.
Ben Floyd
ev**@pondie.com
#############CUT#############
from qt import *
import sys
import threading

class Form1(QMainWindow):
def __init__(self,parent = None,name = None,fl = 0):
QMainWindow.__init__(self,parent,name,fl)
self.setCentralWidget(QWidget(self,"qt_central_wid get"))
self.pushButton1 = QPushButton(self.centralWidget(),"pushButton1")
self.pushButton1.setText("Break Me")
self.connect(self.pushButton1,SIGNAL("clicked()"), self.doSomething)

def doSomething(self):
a = DoStuff()
a.go(self.pushButton1)

class DoStuff:
def go(self, pushbutton_obj):
def runThread():
#DOESNT WORK
pushbutton_obj.setText("Updated")

go = threading.Thread(target=runThread)
go.start()

#WORKS
#pushbutton_obj.setText("Updated")

if __name__ == "__main__":
app = QApplication(sys.argv)
f = Form1()
f.show()
app.setMainWidget(f)
app.exec_loop()
Jul 18 '05 #1
2 1447
Ben Floyd wrote:
Hey everyone,

Why doesn't this work? The code speaks much more clearly than I do,
so i shortened it and pasted it below. Running this
and clicking on 'Break Me' will... freak out the window...


You can not mix GUI threads and non GUI threads.

Just changing text may seem to work, but
even that will get you eventually.

Here's an article that explains how to do it...

http://www.informit.com/articles/article.asp?p=30708


Jul 18 '05 #2
What versions of Python, PyQt, SIP, Qt?

Qt imposes restrictions on which parts of the API can be called in
different threads - check the Qt documentation.

Python has bugs in its thread implementation. These (the ones that affect
PyQt anyway) are fixed in Python 2.4.

Also see the "Support for Threads" section in the PyQt documentation.

Phil
Hey everyone,

Why doesn't this work? The code speaks much more clearly than I do,
so i shortened it and pasted it below. Running this
and clicking on 'Break Me' will... freak out the window...

But... only when the pushbutton_obj.setText("Updated") line
is in the thread. If I comment out the threading code
and uncomment the line below "#WORKS", the button text
updates fine. But in the thread it breaks...

I feel like I'm being stupid here, so ANY suggestions are
much appreciated.

Thanks all.
Ben Floyd
ev**@pondie.com
#############CUT#############
from qt import *
import sys
import threading

class Form1(QMainWindow):
def __init__(self,parent = None,name = None,fl = 0):
QMainWindow.__init__(self,parent,name,fl)
self.setCentralWidget(QWidget(self,"qt_central_wid get"))
self.pushButton1 = QPushButton(self.centralWidget(),"pushButton1")
self.pushButton1.setText("Break Me")
self.connect(self.pushButton1,SIGNAL("clicked()"), self.doSomething)

def doSomething(self):
a = DoStuff()
a.go(self.pushButton1)

class DoStuff:
def go(self, pushbutton_obj):
def runThread():
#DOESNT WORK
pushbutton_obj.setText("Updated")

go = threading.Thread(target=runThread)
go.start()

#WORKS
#pushbutton_obj.setText("Updated")

if __name__ == "__main__":
app = QApplication(sys.argv)
f = Form1()
f.show()
app.setMainWidget(f)
app.exec_loop()
--
http://mail.python.org/mailman/listinfo/python-list

Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
77
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for...
4
by: William Sullivan | last post by:
I have an extremely weird problem that I have no idea how to approach. I have a simple page with a search textbox and a search button. The button causes a postback, where I perform the search and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.