From a18e81dd1311811eb1227cf46d253ae647a9fbdd Mon Sep 17 00:00:00 2001 From: Cristian Maureira-Fredes Date: Fri, 26 Jan 2018 09:47:48 +0100 Subject: 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 --- sources/pyside2/tests/QtWidgets/CMakeLists.txt | 1 + .../tests/QtWidgets/qtabwidgetclear_test.py | 63 ++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 sources/pyside2/tests/QtWidgets/qtabwidgetclear_test.py (limited to 'sources/pyside2/tests') 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() -- cgit v1.2.3