473,324 Members | 2,002 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,324 software developers and data experts.

PyQt, main window can't have reference to application class

Still trying to learn PyQt from a book about several Python GUI
toolkits, I seem to learn first what doesn't work. The following small
script seems to work, but after closing the window I get the error
message "Fatal Python error: PyEval_RestoreThread: NULL tstate".

Without the line "self.app = app" the error goes away. So I suppose the
main window can't have a reference to the application class. Right?
Using the global variable qApp instead of self.app doesn't work either:
qApp seems to be an instance of QApplication, not an instance of HelloApp.

Should the GUI independent actions of the application rather be methods
of the main window? Or methods of some class not derived from QObject,
with a reference to an instance of this class in the main window
instance and not in the application instance? Comparing with Delphi I
suppose this might be the better way. I'd like to use the same class
with different GUI toolkits (Tkinter, wxPython), so all the GUI
independent stuff should be separate.

#!/usr/bin/python
# -*- coding: latin-1 -*-
# hello2.py

import sys
from qt import *

class HelloWindow(QMainWindow):

def __init__(self, app, *args):
QMainWindow.__init__(self, *args)
self.app = app #### this seems to be the problem ####
self.button = QPushButton(self.app.knopftext, self)
# self.button = QPushButton(qApp.knopftext, self) #### won't run at
all ####
self.setCentralWidget(self.button)
self.connect(self.button, SIGNAL('clicked()'), self,
SLOT('close()'))

class HelloApp(QApplication):

def __init__(self, *args):
QApplication.__init__(self, *args)
self.knopftext = 'HelloApp'
self.connect(self, SIGNAL('lastWindowClosed()'),
self, SLOT('quit()'))
self.MainWindow = HelloWindow(self)
self.setMainWidget(self.MainWindow)
self.MainWindow.show()

def main(args):
app = HelloApp(args)
app.exec_loop()

if __name__ == '__main__':
main(sys.argv)

Thank you,
Koczian

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg

Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : Si*************@Bibliothek.Uni-Augsburg.DE

Jul 18 '05 #1
2 3536
On Monday 24 May 2004 3:54 pm, Sibylle Koczian wrote:
Still trying to learn PyQt from a book about several Python GUI
toolkits, I seem to learn first what doesn't work. The following small
script seems to work, but after closing the window I get the error
message "Fatal Python error: PyEval_RestoreThread: NULL tstate".
You have created a circular reference which won't help. The problem doesn't
occur if PyQt is built with SIP v4 - it uses the newer Python thread API.
Without the line "self.app = app" the error goes away. So I suppose the
main window can't have a reference to the application class. Right?
Using the global variable qApp instead of self.app doesn't work either:
qApp seems to be an instance of QApplication, not an instance of HelloApp.
It's the same C++ instance, but they are different types. knopftext is an
attribute of the HelloApp type. qApp is of type QApplication.
Should the GUI independent actions of the application rather be methods
of the main window? Or methods of some class not derived from QObject,
with a reference to an instance of this class in the main window
instance and not in the application instance? Comparing with Delphi I
suppose this might be the better way. I'd like to use the same class
with different GUI toolkits (Tkinter, wxPython), so all the GUI
independent stuff should be separate.

#!/usr/bin/python
# -*- coding: latin-1 -*-
# hello2.py

import sys
from qt import *

class HelloWindow(QMainWindow):

def __init__(self, app, *args):
QMainWindow.__init__(self, *args)
self.app = app #### this seems to be the problem ####
self.button = QPushButton(self.app.knopftext, self)
# self.button = QPushButton(qApp.knopftext, self) #### won't run at
all ####
self.setCentralWidget(self.button)
self.connect(self.button, SIGNAL('clicked()'), self,
SLOT('close()'))

class HelloApp(QApplication):

def __init__(self, *args):
QApplication.__init__(self, *args)
self.knopftext = 'HelloApp'
self.connect(self, SIGNAL('lastWindowClosed()'),
self, SLOT('quit()'))
self.MainWindow = HelloWindow(self)
self.setMainWidget(self.MainWindow)
self.MainWindow.show()

def main(args):
app = HelloApp(args)
app.exec_loop()

if __name__ == '__main__':
main(sys.argv)

Thank you,
Koczian


Phil

Jul 18 '05 #2
Phil Thompson schrieb:
On Monday 24 May 2004 3:54 pm, Sibylle Koczian wrote:
Still trying to learn PyQt from a book about several Python GUI
toolkits, I seem to learn first what doesn't work. The following small
script seems to work, but after closing the window I get the error
message "Fatal Python error: PyEval_RestoreThread: NULL tstate".

You have created a circular reference which won't help. The problem doesn't
occur if PyQt is built with SIP v4 - it uses the newer Python thread API.

But the circular reference would remain, wouldn't it? I still don't see
a way around it: the main window must know about the GUI independent
methods of the application, and those methods should be able to exchange
data with the main window. But I still want to keep the GUI independent
things separate.
Without the line "self.app = app" the error goes away. So I suppose the
main window can't have a reference to the application class. Right?
Using the global variable qApp instead of self.app doesn't work either:
qApp seems to be an instance of QApplication, not an instance of HelloApp.

It's the same C++ instance, but they are different types. knopftext is an
attribute of the HelloApp type. qApp is of type QApplication.

That's what I meant.

Thank you,
Koczian

--
Dr. Sibylle Koczian
Universitaetsbibliothek, Abt. Naturwiss.
D-86135 Augsburg

Tel.: (0821) 598-2400, Fax : (0821) 598-2410
e-mail : Si*************@Bibliothek.Uni-Augsburg.DE

Jul 18 '05 #3

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

Similar topics

4
by: ulysses | last post by:
hi, I'm working in python 5 months. I think it's very cool language. I do a p2p python program GUI. First I make a software by wxpython. But I find wxpython use many many memory. Second I use...
3
by: Fabio | last post by:
Hi all, I'm about to write an application, and I'd like to use PyQt, but before choosing this toolkit I would like to clarify some particular licensing issues; if some user has already touched...
10
by: Michael McGarry | last post by:
Hi, I'm trying to get PyQt up and running under Mac OS X 10.2.8, but can't get past configuring sip. I installed fink's qt3-3.2.3-2 and restarted my shells to get qt3's environment variables...
2
by: gregarican | last post by:
I have an application I'm writing using PyQt. I'm trying to create the various windows by subclassing Qt objects. I have a subclassed QMainWindow as the parent, and then a series of subclassed...
4
by: gregarican | last post by:
I noticed that when I invoked the setCentralWidget() method using PyQt 3.13 on Python 2.3.5 opening and closing a widget associated with a main window would result in a Win32 access violation crash...
4
by: gregarican | last post by:
What's the easiest and cleanest way of having PyQt bring up an external application? In this case I am looking to launch Internet Explorer and bring up a specific URL. I don't care about tracking...
4
by: gregarican | last post by:
I have an PyQt app were I need one of the windows to be able to be opened more than one at a time. When I try to open it I only get one instance at the same time. The main class is the QWidget()...
9
by: anders | last post by:
I am writing a plugin for a piece of software in python, and I want to start up a PyQt GUI in the plugin, without stalling the main thread while the gui is running (later i will want to pass...
3
by: Marcpp | last post by:
Hi, I'm introducing to program in python + pyqt. I have a main window that call a second window (to introduce a info with textedit) when press the second window button I need to return to the main...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.