On Mon, 07 Oct 2013 11:27:56 +1100, Stephen Gava <elgua...@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
diff -r fc7b8711dba0 qpy/QtCore/qpycore_qobject_helpers.cpp
--- a/qpy/QtCore/qpycore_qobject_helpers.cpp	Sat Oct 05 16:44:56 2013 +0100
+++ b/qpy/QtCore/qpycore_qobject_helpers.cpp	Mon Oct 07 13:33:22 2013 +0100
@@ -211,6 +211,7 @@
 
     SIP_BLOCK_THREADS
 
+    PyTypeObject *base_pytype = sipTypeAsPyTypeObject(base);
     PyObject *mro = Py_TYPE(pySelf)->tp_mro;
 
     for (SIP_SSIZE_T i = 0; i < PyTuple_GET_SIZE(mro); ++i)
@@ -224,7 +225,10 @@
 
         if (qstrcmp(pytype->tp_name, _clname) == 0)
         {
-            if (td == base)
+            // The generated type definitions represent the C++ (rather than
+            // Python) hierachy.  If the C++ hierachy doesn't match then the
+            // super-type must be provided by a mixin.
+            if (PyType_IsSubtype(base_pytype, pytype))
                 *sipCpp = sipGetAddress(pySelf);
             else
                 *sipCpp = sipGetMixinAddress(pySelf, td);
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to