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

Jens Persson xerxes2 at gmail.com
Mon Oct 7 09:07:26 BST 2013


This example runs without errors for me on Python2 in Linux.

Greets Jens

On Mon, Oct 7, 2013 at 2:27 AM, 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.
>
> thanks,
> stephen.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20131007/e1fcb047/attachment-0001.html>


More information about the PyQt mailing list