[PyQt] pyqt5.1 baffling exceptions: AttributeError: 'Qxxxxxx' object has no attribute 'QWidget'

Stephen Gava elguavas at gmail.com
Mon Oct 7 01:27:56 BST 2013


Phil, i've attached a simple test case that illustrates this problem, 
here it is inline:

import sys

from PyQt5.QtWidgets import (QApplication,QMainWindow)

class MainWindow(QMainWindow):
     def __init__(self):
         super(MainWindow,self).__init__()
         self.setWindowTitle('test case')
         top_level_window=self.window()
         print(top_level_window)

gui_app=QApplication(sys.argv)
gui_main_window=MainWindow()
gui_main_window.show()
sys.exit(gui_app.exec_())

the result of running the above is an exception:

builtins.AttributeError: 'MainWindow' object has no attribute 'QWidget'

with the traceback stopping in my code at the line where i try to use 
the result of self.window() (by simply printing it).

if you comment out the print(top_level_window) the code runs fine so the 
error happens when trying to _use_ the result of self.window() in any way.

obviously MainWindow is already a top level window, so in the more 
complex code where i'm getting these kind of errors the call to 
QWindow.window() is ocurring in widget (sub)classes that belong to the 
MainWindow.

as i said this error crops up in several places, but seemingly after 
calls to either QWidget.window() or QWidget.childAt() in my code. i'm 
hoping you find some general cause for this, but if you need it i'll try 
to also come up with a simple case where it's triggered after the 
childAt() call.

thanks,
stephen.


On 05/10/13 18:19, Timothy W. Grove wrote:
> Hi Stephen,
>
> I don't really understand the issues here, but I also saw these kinds of
> errors cropping up recently when I moved an application from PyQt4 to
> PyQt5. I think I had at least three different cases of "AttributeError:
> 'Qxxxxxx' object has no attribute 'QWidget'". One case I fixed by not
> giving a parent to the instance I was creating, simply, 'instance =
> SomeWidgetClass(self, parent=None)'; another I fixed by actually giving
> it a parent (!), and for the third case I just had to write different
> code to accomplish my task.
>
> Sorry this isn't very specific but maybe it will give you something to
> try. I'm hoping its just a bug in PyQt5 which will sort itself out
> somewhere down the line ...
>
> Best regards,
> Tim
>
> On 05/10/2013 07:02, Stephen Gava wrote:
>> hi there,
>> i posted an earlier question about one specific instance of this
>> problem which seemed to relate to using QWidget.childAt() (no
>> replies), but now i have the same puzzling issue cropping up in
>> several places in a project i have moved from pyqt4 to pyqt5.
>>
>> under pyqt4 this code ran fine with none of these exceptions.
>>
>> under pyqt5 i'm getting exceptions of the kind detailed in the message
>> title from time to time, ie exceptions where the final error message is:
>>
>>  AttributeError: 'Qxxxxxx' object has no attribute 'QWidget'
>>
>> where Qxxxxxx is some kind of widget (in one instance QLabel, in
>> another couple of cases QMainWindow).
>>
>> these errors seem like they might be comming from pyqt5 itself, as i
>> don't reference QWidget as an attribute of any labels or mainwindows
>> in my own code, however the tracebacks i get only follow the stack in
>> my own code, in one instance this exception is thrown after a call to
>> QWidget.childAt() and in some other instances after calls to
>> QWidget.window()  (which was Qwidget.topLevelWidget() in pyqt4).
>>
>> as i said the pyqt4 version never throws these exceptions, and i can't
>> find anything in my code that should be causing this under pyqt5...
>>
>> does anyone have any advice on how i can at least try to work out
>> where the issue is coming from? it's definitely caused by something
>> new/different in ptqt5.
>>
>> thanks,
>> stephen.
>> _______________________________________________
>> PyQt mailing list    PyQt at riverbankcomputing.com
>> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
>>
>
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: zz_test_case.py
Type: text/x-python
Size: 388 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20131007/b689fd0e/attachment.py>


More information about the PyQt mailing list