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

Phil Thompson phil at riverbankcomputing.com
Mon Oct 7 13:36:18 BST 2013


On Mon, 07 Oct 2013 11:27:56 +1100, Stephen Gava <elguavas at gmail.com>
wrote:
> 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.

Hopefully fixed in tonight's PyQt5 snapshot, or try the attached patch.

Thanks,
Phil
-------------- next part --------------
A non-text attachment was scrubbed...
Name: qpycore_qobject_helpers.cpp.patch
Type: text/x-diff
Size: 940 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20131007/a2e0d1f9/attachment.patch>


More information about the PyQt mailing list