aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Maureira-Fredes <cristian.maureira-fredes@qt.io>2018-01-26 09:47:48 +0100
committerSimo Fält <simo.falt@qt.io>2018-02-02 10:21:23 +0000
commita18e81dd1311811eb1227cf46d253ae647a9fbdd (patch)
treea5a948f28441163605da26a04b0e36af55980fb2
parent27e24a733b8a65623683b00c0764ef00d05fa397 (diff)
Fix QTabWidget.clear to avoid double obj removal
Replacing shiboken call setParent with releaseOwnership so Python will not delete the underlying C++ object. A test case is provided to check that the error is not happening. Task-number: PYSIDE-213 Change-Id: Ic0f383c3d93b905885f76788d32d62ba37ed9d2f Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
-rw-r--r--sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml7
-rw-r--r--sources/pyside2/tests/QtWidgets/CMakeLists.txt1
-rw-r--r--sources/pyside2/tests/QtWidgets/qtabwidgetclear_test.py63
3 files changed, 69 insertions, 2 deletions
diff --git a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
index 9d3e70be2..1663e4f4e 100644
--- a/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
+++ b/sources/pyside2/PySide2/QtWidgets/typesystem_widgets_common.xml
@@ -2507,10 +2507,13 @@
</modify-function>
<modify-function signature="clear()">
<inject-code class="target" position="beginning">
+ Shiboken::BindingManager&amp; bm = Shiboken::BindingManager::instance();
for (int i = 0; i &lt; %CPPSELF.count(); i++) {
QWidget* widget = %CPPSELF.widget(i);
- Shiboken::AutoDecRef pyWidget(%CONVERTTOPYTHON[QWidget*](widget));
- Shiboken::Object::setParent(0, pyWidget);
+ if (bm.hasWrapper(widget)) {
+ Shiboken::AutoDecRef pyWidget(%CONVERTTOPYTHON[QWidget*](widget));
+ Shiboken::Object::releaseOwnership(pyWidget);
+ }
}
%CPPSELF.%FUNCTION_NAME();
</inject-code>
diff --git a/sources/pyside2/tests/QtWidgets/CMakeLists.txt b/sources/pyside2/tests/QtWidgets/CMakeLists.txt
index 3c31b1d7d..46a07c9a3 100644
--- a/sources/pyside2/tests/QtWidgets/CMakeLists.txt
+++ b/sources/pyside2/tests/QtWidgets/CMakeLists.txt
@@ -117,6 +117,7 @@ PYSIDE_TEST(qstring_qkeysequence_test.py)
PYSIDE_TEST(qstyle_test.py)
PYSIDE_TEST(qtableview_test.py)
PYSIDE_TEST(qtabwidget_test.py)
+PYSIDE_TEST(qtabwidgetclear_test.py)
PYSIDE_TEST(qtextedit_test.py)
PYSIDE_TEST(qtextedit_signal_test.py)
PYSIDE_TEST(qtoolbar_test.py)
diff --git a/sources/pyside2/tests/QtWidgets/qtabwidgetclear_test.py b/sources/pyside2/tests/QtWidgets/qtabwidgetclear_test.py
new file mode 100644
index 000000000..8e9b36fab
--- /dev/null
+++ b/sources/pyside2/tests/QtWidgets/qtabwidgetclear_test.py
@@ -0,0 +1,63 @@
+#############################################################################
+##
+## Copyright (C) 2018 The Qt Company Ltd.
+## Contact: https://www.qt.io/licensing/
+##
+## This file is part of the test suite of PySide2.
+##
+## $QT_BEGIN_LICENSE:GPL-EXCEPT$
+## Commercial License Usage
+## Licensees holding valid commercial Qt licenses may use this file in
+## accordance with the commercial license agreement provided with the
+## Software or, alternatively, in accordance with the terms contained in
+## a written agreement between you and The Qt Company. For licensing terms
+## and conditions see https://www.qt.io/terms-conditions. For further
+## information use the contact form at https://www.qt.io/contact-us.
+##
+## GNU General Public License Usage
+## Alternatively, this file may be used under the terms of the GNU
+## General Public License version 3 as published by the Free Software
+## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+## included in the packaging of this file. Please review the following
+## information to ensure the GNU General Public License requirements will
+## be met: https://www.gnu.org/licenses/gpl-3.0.html.
+##
+## $QT_END_LICENSE$
+##
+#############################################################################
+
+import unittest
+
+from PySide2.QtWidgets import QMainWindow, QTabWidget, QTextEdit, QSplitter
+from helper import UsesQApplication
+
+class TabWidgetClear(QMainWindow):
+ def __init__(self):
+ QMainWindow.__init__(self)
+ self.tabWidget = QTabWidget(self)
+ self.setCentralWidget(self.tabWidget)
+ self.editBox = QTextEdit(self)
+ self.tabWidget.addTab(self.getSplitter(), 'Test')
+
+ def getSplitter(self):
+ splitter = QSplitter()
+ splitter.addWidget(self.editBox)
+ return splitter
+
+ def toggle(self):
+ self.tabWidget.clear()
+ self.getSplitter()
+
+class TestTabWidgetClear(UsesQApplication):
+
+ def testClear(self):
+ self.window = TabWidgetClear()
+ self.window.show()
+ try:
+ self.window.toggle()
+ except RuntimeError as e:
+ # This should never happened, PYSIDE-213
+ raise e
+
+if __name__ == '__main__':
+ unittest.main()