QPaintDevice: Must construct a QApplication before a QPaintDevice

B

boris.smirnov

Hi all,

I have a python script that works without any problem on Windows but
with error:

QPaintDevice: Must construct a QApplication before a QPaintDevice

on Linux.

Where could be the problem?

Thanks.
Boris
 
D

Diez B. Roggisch

Hi all,

I have a python script that works without any problem on Windows but
with error:

QPaintDevice: Must construct a QApplication before a QPaintDevice

on Linux.

Where could be the problem?

This is the problem:

You Must construct a QApplication before a QPaintDevice

Diez
 
B

boris.smirnov

This is the problem:

You Must construct a QApplication before a QPaintDevice

Diez

Yes that I can deduce, but why I'm asking is why it's different on
Windows and Linux. Should it not be platform independent?
 
D

Diez B. Roggisch

Yes that I can deduce, but why I'm asking is why it's different on
Windows and Linux. Should it not be platform independent?

It should be. I've got no idea why it seems to work on windows but I can say
one thing for sure: that would be an artifact that you shouldn't rely on.
In Qt, you _always_ need a QApplication for anything. So just do as it
requires you to do: first, construct a QApplication. Then things will work.

Diez
 
B

boris.smirnov

It should be. I've got no idea why it seems to work on windows but I can say
one thing for sure: that would be an artifact that you shouldn't rely on.
In Qt, you _always_ need a QApplication for anything. So just do as it
requires you to do: first, construct a QApplication. Then things will work.

Diez

Hmm, as I see the code, I do construct QApplication as first

if __name__ == '__main__':
a = QApplication (sys.argv)
mywidget = Optimizer()
a.setMainWidget (mywidget)
mywidget.show()
Update_StatusLine(mywidget)
mywidget.setStartconfig()
a.exec_loop ()
 
D

Diez B. Roggisch

Hmm, as I see the code, I do construct QApplication as first

if __name__ == '__main__':
a = QApplication (sys.argv)
mywidget = Optimizer()
a.setMainWidget (mywidget)
mywidget.show()
Update_StatusLine(mywidget)
mywidget.setStartconfig()
a.exec_loop ()

I don't see any QPaintDevice here. Where does that come from? You need to
give more information, a stack trace and a reduced example exhibiting the
behaviour.

Diez
 
S

shredwheat

I don't see any QPaintDevice here. Where does that come from? You need to
give more information, a stack trace and a reduced example exhibiting the
behaviour.

QWidget is derived from QPaintDevice, under Qt, no widgets can be
instantiated before the QApplication.

This source snippet looks like it should be working. If the exception
is happening inside Optimizer() than something really unsusual is
happening. I suspect there is python code somewhere else happening at
import time that is creating a widget. The exception traceback should
show you right where that would be.
 
B

boris.smirnov

shredwheat napísal(a):
QWidget is derived from QPaintDevice, under Qt, no widgets can be
instantiated before the QApplication.

This source snippet looks like it should be working. If the exception
is happening inside Optimizer() than something really unsusual is
happening. I suspect there is python code somewhere else happening at
import time that is creating a widget. The exception traceback should
show you right where that would be.

Thanks for the reply.
I'm not so familiar with python so could you explain me how to use and
become the exception traceback. I've tried today to read something for
the beginners about traceback and stack trace in the forum, but I
haven't found something really understadable for met.
Some piece of code for my case will help :) and I want to learn it of
course.

Thanks.
Boris
 
S

shredwheat

When your programs stops with the error, it should also be printing a
stack trace. This is a list of all the functions that have been called
when Python had the problem.

You shouldn't have to do anything extra to get the stack trace.
 
P

Phil Thompson

When your programs stops with the error, it should also be printing a
stack trace. This is a list of all the functions that have been called
when Python had the problem.

You shouldn't have to do anything extra to get the stack trace.

The error is raised in Qt and aborts immediately. It never gets back to Python
to generate a trace.

He needs to produce a short and complete test which demonstrates the problem,
then we can point out where the QPaintDevice is being created.

Phil
 
B

boris.smirnov

The error is raised in Qt and aborts immediately. It never gets back to Python
to generate a trace.

He needs to produce a short and complete test which demonstrates the problem,
then we can point out where the QPaintDevice is being created.

Phil

OK, but before I do a complete test, could anybody tell/explain me why
the same file is working on Windows?
Did anybody already meet with something similar Win vs. Linux?

b.
 
B

boris.smirnov

OK, but before I do a complete test, could anybody tell/explain me why
the same file is working on Windows?
Did anybody already meet with something similar Win vs. Linux?

b.

Here is my simple script:

import sys
from qt import *
class Optimizer(QWidget):
def __init__(self, parent = 0):
QWidget.__init__(self)
QGridLayout(self)
if __name__ == '__main__':
a = QApplication (sys.argv)
mywidget = Optimizer()
a.exec_loop()

This produces this:
python qt_script_bs_070228.py
QPaintDevice: Must construct a QApplication before a QPaintDevice

Any suggestions here?
Thanks



BTW: One question:
when I use "import qt" instead of "from qt import *" I get this error:
Traceback (most recent call last):
File "mscarideidtool_bs_070228.py", line 4, in ?
class Optimizer(QWidget):
NameError: name 'QWidget' is not defined

What is the difference between "import qt" and "from qt import *" ? I
thought that these are the same.
 
P

Phil Thompson

Here is my simple script:

import sys
from qt import *
class Optimizer(QWidget):
def __init__(self, parent = 0):
QWidget.__init__(self)
QGridLayout(self)
if __name__ == '__main__':
a = QApplication (sys.argv)
mywidget = Optimizer()
a.exec_loop()

This produces this:

QPaintDevice: Must construct a QApplication before a QPaintDevice

Any suggestions here?

It works fine for me.
Thanks



BTW: One question:
when I use "import qt" instead of "from qt import *" I get this error:
Traceback (most recent call last):
File "mscarideidtool_bs_070228.py", line 4, in ?
class Optimizer(QWidget):
NameError: name 'QWidget' is not defined

What is the difference between "import qt" and "from qt import *" ? I
thought that these are the same.

The first creates a new namespace called "qt" and imports the module's objects
into it. To reference those objects you have to include the namespace name.

The second imports the module's objects into the current namespace.

Phil
 
B

boris.smirnov

It works fine for me.




The first creates a new namespace called "qt" and imports the module's objects
into it. To reference those objects you have to include the namespace name.

The second imports the module's objects into the current namespace.

Phil- Hide quoted text -

- Show quoted text -

OK, I have to apologize because I didn't mention that I use python
version 2.2.1, could it be the problem here? Bugs or something? I have
to use this version since it was delivered with a software that we use
here.
 
P

Phil Thompson

OK, I have to apologize because I didn't mention that I use python
version 2.2.1, could it be the problem here? Bugs or something? I have
to use this version since it was delivered with a software that we use
here.

So what versions of Qt, PyQt and SIP are you using? Were these included with
the software you are using? If so, what is that software?

Phil
 
B

boris.smirnov

So what versions of Qt, PyQt and SIP are you using? Were these included with
the software you are using? If so, what is that software?

Phil- Hide quoted text -

- Show quoted text -

Stupid question but how can I find out what are the versions of those?
I only found qt.py file and there was this:
# Generated by SIP 3.3 (build 25) on Fri Jul 26 12:44:13 2002
The version of PyQt and SIP can't find out, but there is a directory
PyQt wit .pyc files and SIP.h file.

The sofware is MSC.ADAMS from msc.software

b.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top