From f01a4b7d87c926dffb68aadb27b95c05dc22100c Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 10 Jul 2012 18:24:51 -0400 Subject: [PATCH 01/37] Add README file specific to CTK github fork Update list of features associated with patched-2 and patched-3 branches --- README.md | 123 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 00000000..0d7595b2 --- /dev/null +++ b/README.md @@ -0,0 +1,123 @@ +PythonQt +======== + +Overview +-------- + +PythonQt is a dynamic [Python](http://www.python.org) binding for [Qt](http://qt.nokia.com). +It offers an easy way to embed the Python scripting language into +your Qt applications. It makes heavy use of the QMetaObject system and thus requires Qt4.x. + +This project is a fork of the [official PythonQt](http://pythonqt.sourceforge.net/) repository +hosted on sourceforge. + +It serves as *staging area* to contain patches that will then be contributed back to the +official repository. + +Prerequisites +------------- + +* CMake 2.8.x +* Qt 4.6.2 or above + +Build instructions +------------------ + +By default, the `patched-3` version will be checked out. + +``` +git clone git://github.com/commontk/PythonQt.git +mkdir PythonQt-build +cd PythonQt-build +cmake -DQT_QMAKE_EXECUTABLE:FILEPATH=/path/to/qmake ../PythonQt +make +``` + +Additional configure options are: + +* `CMAKE_BUILD_TYPE`: Debug, Release, RelWithDebInfo or MinSizeRel +* `PythonQt_DEBUG`: Enable/Disable PythonQt debug output +* `PythonQt_Wrap_QtAll`: Make all Qt components available in python +* `PythonQt_Wrap_Qt`: Build PythonQt wrapper associated with ``. Possible `` are `gui`, `network`, `opengl`, `sql`, `uitools`, `webkit`, `xml`, `xmlpatterns`. + +Available branches +------------------ + +This repository contains three branches: +* Based on [r244](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=244) + +### patched-3 +* Backported: + * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/e2dce4b...patched-2) `patched-2` branch have been backported upstream: [r241](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=241), [r242](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=242), [r243](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=243) + +### patched-2 + +* Based on [r228](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=228) +* List of features: + * At configuration time, detect the Qt version used and seamlessly compile the appropriate wrappers (Qt 4.8, 4.7 or 4.6). + * Add method allowing to know if a python error occurred: [5935f29](https://github.com/commontk/PythonQt/commit/5935f29978deed892a13ddef02cb14c205c6124d) + * Also add associated method "resetErrorFlag": [a386dc60](https://github.com/commontk/PythonQt/commit/a386dc60f71c15e67c611bc31b26cee756ed833a) + * Fix compilation issue on VS2010 when PythonQt Debug build against python Release: [7e1e07f](https://github.com/commontk/PythonQt/commit/7e1e07f34b2420e420e2858e5ea9a49fe1e0d235) + * Add option Add PythonQt_Wrap_QtAll: [97df3b0](https://github.com/commontk/PythonQt/commit/97df3b0845b3f5c987d3141a9e651436882f5913) and [9104fa9](https://github.com/commontk/PythonQt/commit/9104fa924859f4a865016f2138c06ec856f449d4) + * Ensure all 4.8 generated wrappers are considered: [654f324](https://github.com/commontk/PythonQt/commit/654f3249d1cf3f3ff674b2ff6cca7a2ef3517f60) + * Update "PythonQtPythonInclude.h" to avoid build error on recent MacOSX: [7b8ee130](https://github.com/commontk/PythonQt/commit/7b8ee13058bc0b366983ce8228612e75f8dd9ca8) and [47738f9c](https://github.com/commontk/PythonQt/commit/47738f9c8c5d3ffa77c8f2e1844f899e5b548f0c) + * Update "PythonQtPythonInclude.h" to fix windows build issue when PythonQt Debug build against python Release[6366f00](https://github.com/commontk/PythonQt/commit/6366f002a93aa238c55f58de949d09c552cda5a9) + * Optionally include CTestUseLaunchers: [211440](https://github.com/commontk/PythonQt/commit/2114405a47836b3fb16a3f66fec6a02184f32e71) + * Add SystemExit exception handler. If enabled, the signal "systemExitExceptionRaised" will be emitted. It gives application the opportunity to cleanup and terminate nicely: [3c84463d](https://github.com/commontk/PythonQt/commit/3c84463d3fc4a99c94207c1116ba33d7a412a95f) + * Add "isatty" function to StdOutRedirect. Needed by some logging frame: [7132dba9](https://github.com/commontk/PythonQt/commit/7132dba93064c2a02591b42305fecdd5d59702d3) +* Backported: + * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/svn-mirror...patched) `patched` branch have been backported upstream: [r200](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=200), [r201](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=201), [r202](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=202), [r203](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=203), [r204](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=204) + * CMake option `PYTHONQT_USE_VTK` has been removed ([r205](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=205)), the foreign wrapper mechanism should be used: [r206](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=206) + +### patched + +* Based on [r193](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=193) +* List of features: + * CMake'ified PythonQt project + * CMake'ified PythonQt/generator project + * Add `dPython.h` file, it provides the ability to link against release python with a debug build of your project. + * Option `PYTHONQT_USE_VTK` CMake option allowing to teach PythonQt how to deal with `vtkObject` + * Stdin can optionally be redirected to a custom callback + * [More details](https://github.com/commontk/PythonQt/compare/svn-mirror...patched) + +### svn-mirror + +* SVN history imported using `git-svn` + +Contributing +------------ + +Once you've made your great commits: + +1. [Fork][fk] PythonQt +2. Create a topic branch - `git checkout -b my_branch` +3. Push to your branch - `git push origin my_branch` +4. Create an [Issue][is] with a link to your branch +5. That's it! + + +Meta +---- + +* Code: `git clone git://github.com/commontk/PythonQt.git` +* Home: +* Bugs: + +License +------- + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +[fk]: http://help.github.com/forking/ +[is]: http://github.com/jcfr/qJobManager/issues + From 9c135e3f195fd9da88ac95bc370ed081147c8dba Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 28 May 2013 00:32:03 -0400 Subject: [PATCH 02/37] Fix "_invalid_parameter_noinfo_noreturn" link error By ensuring that "undef" of _DEBUG macro is not done before system includes, it fixes the issue. This commit is based on what has been within VTK. See https://github.com/Kitware/VTK/commit/81d4a72c1195437403f1772559c9c28978818f03 See #9 Thanks @Neosettler for testing the patch. Reported-by: Neosettler --- src/PythonQtPythonInclude.h | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/PythonQtPythonInclude.h b/src/PythonQtPythonInclude.h index 20d5ab8e..be8d0e00 100644 --- a/src/PythonQtPythonInclude.h +++ b/src/PythonQtPythonInclude.h @@ -60,7 +60,7 @@ // release Python DLL if it is available by undefining _DEBUG while // including Python.h #if defined(PYTHONQT_USE_RELEASE_PYTHON_FALLBACK) && defined(_DEBUG) -#undef _DEBUG +# define PYTHONQT_UNDEF_DEBUG // Include these low level headers before undefing _DEBUG. Otherwise when doing // a debug build against a release build of python the compiler will end up // including these low level headers without DEBUG enabled, causing it to try @@ -80,14 +80,17 @@ # include # include # include -#if defined(_MSC_VER) && _MSC_VER >= 1400 -#define _CRT_NOFORCE_MANIFEST 1 -#define _STL_NOFORCE_MANIFEST 1 +# undef _DEBUG +# if defined(_MSC_VER) && _MSC_VER >= 1400 +# define _CRT_NOFORCE_MANIFEST 1 +# define _STL_NOFORCE_MANIFEST 1 +# endif #endif + #include -#define _DEBUG -#else -#include + +#ifdef PYTHONQT_UNDEF_DEBUG +# define _DEBUG #endif // get Qt keywords back From 44fb97bfea369e4f04a0afe8bd817cd566ba6cc0 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 9 Sep 2013 22:15:45 -0400 Subject: [PATCH 03/37] Update Readme.md to use new url format for svn revision reference --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 0d7595b2..67624a4e 100644 --- a/README.md +++ b/README.md @@ -44,15 +44,18 @@ Available branches ------------------ This repository contains three branches: -* Based on [r244](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=244) +* Based on [r245](http://sourceforge.net/p/pythonqt/code/245/) + +### patched-4 +* Based on patched-3 + [r245](http://sourceforge.net/p/pythonqt/code/245/) ### patched-3 * Backported: - * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/e2dce4b...patched-2) `patched-2` branch have been backported upstream: [r241](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=241), [r242](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=242), [r243](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=243) + * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/e2dce4b...patched-2) `patched-2` branch have been backported upstream: [r241](http://sourceforge.net/p/pythonqt/code/241/), [r242](http://sourceforge.net/p/pythonqt/code/242/), [r243](http://sourceforge.net/p/pythonqt/code/243/) ### patched-2 -* Based on [r228](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=228) +* Based on [r228](http://sourceforge.net/p/pythonqt/code/228/) * List of features: * At configuration time, detect the Qt version used and seamlessly compile the appropriate wrappers (Qt 4.8, 4.7 or 4.6). * Add method allowing to know if a python error occurred: [5935f29](https://github.com/commontk/PythonQt/commit/5935f29978deed892a13ddef02cb14c205c6124d) @@ -66,12 +69,12 @@ This repository contains three branches: * Add SystemExit exception handler. If enabled, the signal "systemExitExceptionRaised" will be emitted. It gives application the opportunity to cleanup and terminate nicely: [3c84463d](https://github.com/commontk/PythonQt/commit/3c84463d3fc4a99c94207c1116ba33d7a412a95f) * Add "isatty" function to StdOutRedirect. Needed by some logging frame: [7132dba9](https://github.com/commontk/PythonQt/commit/7132dba93064c2a02591b42305fecdd5d59702d3) * Backported: - * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/svn-mirror...patched) `patched` branch have been backported upstream: [r200](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=200), [r201](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=201), [r202](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=202), [r203](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=203), [r204](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=204) - * CMake option `PYTHONQT_USE_VTK` has been removed ([r205](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=205)), the foreign wrapper mechanism should be used: [r206](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=206) + * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/svn-mirror...patched) `patched` branch have been backported upstream: [r200](http://sourceforge.net/p/pythonqt/code/200/), [r201](http://sourceforge.net/p/pythonqt/code/201/), [r202](http://sourceforge.net/p/pythonqt/code/202/), [r203](http://sourceforge.net/p/pythonqt/code/203/), [r204](http://sourceforge.net/p/pythonqt/code/204/) + * CMake option `PYTHONQT_USE_VTK` has been removed ([r205](http://sourceforge.net/p/pythonqt/code/205/)), the foreign wrapper mechanism should be used: [r206](http://sourceforge.net/p/pythonqt/code/206/) ### patched -* Based on [r193](http://pythonqt.svn.sourceforge.net/viewvc/pythonqt?view=revision&revision=193) +* Based on [r193](http://sourceforge.net/p/pythonqt/code/193/) * List of features: * CMake'ified PythonQt project * CMake'ified PythonQt/generator project From 22c9bd94a9512df1a4d8746ff49b47bc32023bd3 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 10 Sep 2013 02:36:26 -0400 Subject: [PATCH 04/37] Add CMake testing support Disabled by default to keep behavior consistent with previous CMake'ified version. --- CMakeLists.txt | 38 +++++++++++++++++++++++++++++++++++--- README.md | 2 ++ 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5dfed026..9e248dc1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,8 +11,6 @@ cmake_minimum_required(VERSION 2.8) project(PythonQt) #----------------------------------------------------------------------------- -include(CTestUseLaunchers OPTIONAL) - #----------------------------------------------------------------------------- # Python libraries @@ -71,7 +69,9 @@ if(QT4_FOUND) endif() set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}}) endforeach() - + + set(QT_USE_QTTEST ${BUILD_TESTING}) + include(${QT_USE_FILE}) else() message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable") @@ -238,3 +238,35 @@ install(TARGETS PythonQt LIBRARY DESTINATION lib ARCHIVE DESTINATION lib) install(FILES ${headers} DESTINATION include/PythonQt) + +#----------------------------------------------------------------------------- +# Testing + +option(BUILD_TESTING "Build the testing tree." OFF) +include(CTest) + +if(BUILD_TESTING) + create_test_sourcelist(test_sources PythonQtCppTests.cpp + tests/PythonQtTestMain.cpp + ) + + list(APPEND test_sources + tests/PythonQtTests.cpp + tests/PythonQtTests.h + ) + + QT4_WRAP_CPP(test_sources + tests/PythonQtTests.h + ) + + set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain") + + add_executable(PythonQtCppTests ${test_sources}) + target_link_libraries(PythonQtCppTests PythonQt) + + add_test( + NAME tests_PythonQtTestMain + COMMAND ${Slicer_LAUNCH_COMMAND} $ tests/PythonQtTestMain + ) +endif() + diff --git a/README.md b/README.md index 67624a4e..b72c0162 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,8 @@ This repository contains three branches: ### patched-4 * Based on patched-3 + [r245](http://sourceforge.net/p/pythonqt/code/245/) +* List of features: + * Add BUILD_TESTING option disabled by default to keep behavior consistent with previous version. ### patched-3 * Backported: From 6da0b4edc2698b40d19932512656907485da1919 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 10 Sep 2013 02:49:23 -0400 Subject: [PATCH 05/37] Revert part of r91 preventing QFlags from being wrapped By checking if an enum member has already been cached it is not required anymore to skip it if is a QFlags. Additionally, the wrapping of QFlags can now be done by using only Q_FLAGS without having a corresponding Q_ENUMS. --- README.md | 2 ++ src/PythonQtClassInfo.cpp | 12 ++++++------ tests/PythonQtTests.cpp | 33 +++++++++++++++++++++++++++++++++ tests/PythonQtTests.h | 30 ++++++++++++++++++++++++++++++ 4 files changed, 71 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b72c0162..9e43ea73 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,8 @@ This repository contains three branches: * Based on patched-3 + [r245](http://sourceforge.net/p/pythonqt/code/245/) * List of features: * Add BUILD_TESTING option disabled by default to keep behavior consistent with previous version. + * Do not exclude enums from wrapping if they are QFlags. + * Ensure enums added using only Q_FLAGS without corresponding Q_ENUMS are wrapped. ### patched-3 * Backported: diff --git a/src/PythonQtClassInfo.cpp b/src/PythonQtClassInfo.cpp index a75d7644..d26453c8 100644 --- a/src/PythonQtClassInfo.cpp +++ b/src/PythonQtClassInfo.cpp @@ -273,9 +273,12 @@ bool PythonQtClassInfo::lookForEnumAndCache(const QMetaObject* meta, const char* int enumCount = meta->enumeratorCount(); for (int i=0;ienumerator(i); - // we do not want flags, they will cause our values to appear two times - if (e.isFlag()) continue; - + if (_cachedMembers.contains(memberName)) { + #ifdef PYTHONQT_DEBUG + std::cout << "cached enum " << memberName << " on " << meta->className() << std::endl; + #endif + continue; + } for (int j=0; j < e.keyCount(); j++) { if (qstrcmp(e.key(j), memberName)==0) { PyObject* enumType = findEnumWrapper(e.name()); @@ -536,9 +539,6 @@ QStringList PythonQtClassInfo::memberList() for (int i = 0; ienumeratorCount(); i++) { QMetaEnum e = meta->enumerator(i); l << e.name(); - // we do not want flags, they will cause our values to appear two times - if (e.isFlag()) continue; - for (int j=0; j < e.keyCount(); j++) { l << QString(e.key(j)); } diff --git a/tests/PythonQtTests.cpp b/tests/PythonQtTests.cpp index 30d6932d..65296604 100644 --- a/tests/PythonQtTests.cpp +++ b/tests/PythonQtTests.cpp @@ -298,8 +298,21 @@ void PythonQtTestSlotCalling::testCppFactory() // with int overload to check overloading QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObject2\na = PQCppObject2()\nif a.testEnumFlag3(PQCppObject2.TestEnumValue2)==PQCppObject2.TestEnumValue2: obj.setPassed();\n")); + PythonQt::self()->registerCPPClass("PQCppObjectQFlagOnly",NULL,NULL, PythonQtCreateObject); + + + // local enum (decorated) + QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObjectQFlagOnly\na = PQCppObjectQFlagOnly()\nprint a.testEnumFlag1\nif a.testEnumFlag1(PQCppObjectQFlagOnly.TestEnumValue2)==PQCppObjectQFlagOnly.TestEnumValue2: obj.setPassed();\n")); + + // enum with namespace (decorated) + QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObjectQFlagOnly\na = PQCppObjectQFlagOnly()\nif a.testEnumFlag2(PQCppObjectQFlagOnly.TestEnumValue2)==PQCppObjectQFlagOnly.TestEnumValue2: obj.setPassed();\n")); + // with int overload to check overloading + QVERIFY(_helper->runScript("obj.testNoArg()\nfrom PythonQt.private import PQCppObjectQFlagOnly\na = PQCppObjectQFlagOnly()\nif a.testEnumFlag3(PQCppObjectQFlagOnly.TestEnumValue2)==PQCppObjectQFlagOnly.TestEnumValue2: obj.setPassed();\n")); + } +// PQCppObject2Decorator + PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag1(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) { return flag; } @@ -316,6 +329,26 @@ PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppOb return flag; } +// PQCppObjectQFlagOnlyDecorator + +PQCppObjectQFlagOnlyDecorator::TestEnumFlag PQCppObjectQFlagOnlyDecorator::testEnumFlag1(PQCppObjectQFlagOnly* obj, PQCppObjectQFlagOnlyDecorator::TestEnumFlag flag) { + return flag; +} + +PQCppObjectQFlagOnly::TestEnumFlag PQCppObjectQFlagOnlyDecorator::testEnumFlag2(PQCppObjectQFlagOnly* obj, PQCppObjectQFlagOnly::TestEnumFlag flag) { + return flag; +} + +// with int overload +PQCppObjectQFlagOnlyDecorator::TestEnumFlag PQCppObjectQFlagOnlyDecorator::testEnumFlag3(PQCppObjectQFlagOnly* obj, int flag) { + return (TestEnumFlag)-1; +} +PQCppObjectQFlagOnlyDecorator::TestEnumFlag PQCppObjectQFlagOnlyDecorator::testEnumFlag3(PQCppObjectQFlagOnly* obj, PQCppObjectQFlagOnlyDecorator::TestEnumFlag flag) { + return flag; +} + +// PythonQtTestSlotCalling + void PythonQtTestSlotCalling::testMultiArgsSlotCall() { QVERIFY(_helper->runScript("if obj.getMultiArgs(12,47.11,'test')==(12,47.11,'test'): obj.setPassed();\n")); diff --git a/tests/PythonQtTests.h b/tests/PythonQtTests.h index ece44596..3f06807d 100644 --- a/tests/PythonQtTests.h +++ b/tests/PythonQtTests.h @@ -293,6 +293,36 @@ class PQCppObject2Decorator : public QObject { }; +typedef PQCppObject2 PQCppObjectQFlagOnly; + +class PQCppObjectQFlagOnlyDecorator : public QObject { + Q_OBJECT + +public: + Q_FLAGS(TestEnumFlag) + + enum TestEnumFlag { + TestEnumValue1 = 0, + TestEnumValue2 = 1 + }; + + Q_DECLARE_FLAGS(TestEnum, TestEnumFlag) + + public slots: + PQCppObjectQFlagOnly* new_PQCppObjectQFlagOnly() { + return new PQCppObjectQFlagOnly(); + } + + TestEnumFlag testEnumFlag1(PQCppObjectQFlagOnly* obj, TestEnumFlag flag); + + PQCppObjectQFlagOnly::TestEnumFlag testEnumFlag2(PQCppObjectQFlagOnly* obj, PQCppObjectQFlagOnly::TestEnumFlag flag); + + // with int overload + TestEnumFlag testEnumFlag3(PQCppObjectQFlagOnly* obj, int flag); + TestEnumFlag testEnumFlag3(PQCppObjectQFlagOnly* obj, TestEnumFlag flag); + +}; + class PQUnknownValueObject { public: From d213b781f2fa9fc65ac5e90f33b93c450364a98d Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Wed, 21 May 2014 18:17:20 -0400 Subject: [PATCH 06/37] fix problem in CMake error message Remove unmatched '${' in error message. CMake itself might not have minded, but it confuses the heck out of both katepart and vim syntax highlighting. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9e248dc1..19fd6e54 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,7 +65,7 @@ if(QT4_FOUND) foreach(qtlib network opengl sql svg uitools webkit xml xmlpatterns) string(TOUPPER ${qtlib} qtlib_uppercase) if (NOT ${QT_QT${qtlib_uppercase}_FOUND}) - message(FATAL_ERROR "QT_QT${${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}") + message(FATAL_ERROR "QT_QT${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}") endif() set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}}) endforeach() From 809b82168308b09a25c2a59d2e249ae8c0645772 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Wed, 21 May 2014 18:22:58 -0400 Subject: [PATCH 07/37] allow specifying install directories Add variables to allow users to override the default install directories, and also respect LIB_SUFFIX by default. --- CMakeLists.txt | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 19fd6e54..fcd2c70b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,22 @@ add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK) #----------------------------------------------------------------------------- # Build options +if(NOT DEFINED PythonQt_INSTALL_RUNTIME_DIR) + set(PythonQt_INSTALL_RUNTIME_DIR bin) +endif() + +if(NOT DEFINED PythonQt_INSTALL_LIBRARY_DIR) + set(PythonQt_INSTALL_LIBRARY_DIR lib${LIB_SUFFIX}) +endif() + +if(NOT DEFINED PythonQt_INSTALL_ARCHIVE_DIR) + set(PythonQt_INSTALL_ARCHIVE_DIR lib${LIB_SUFFIX}) +endif() + +if(NOT DEFINED PythonQt_INSTALL_INCLUDE_DIR) + set(PythonQt_INSTALL_INCLUDE_DIR include/PythonQt) +endif() + option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF) set(qtlibs core gui network opengl sql svg uitools webkit xml xmlpatterns) @@ -234,10 +250,10 @@ target_link_libraries(PythonQt # Install library (on windows, put the dll in 'bin' and the archive in 'lib') install(TARGETS PythonQt - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) -install(FILES ${headers} DESTINATION include/PythonQt) + RUNTIME DESTINATION ${PythonQt_INSTALL_RUNTIME_DIR} + LIBRARY DESTINATION ${PythonQt_INSTALL_LIBRARY_DIR} + ARCHIVE DESTINATION ${PythonQt_INSTALL_ARCHIVE_DIR}) +install(FILES ${headers} DESTINATION ${PythonQt_INSTALL_INCLUDE_DIR}) #----------------------------------------------------------------------------- # Testing From 3fa4ecc79e920a5d8e5033476398f1b3d24f1172 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Wed, 21 May 2014 18:24:23 -0400 Subject: [PATCH 08/37] remove trailing spaces in CMakeLists.txt --- CMakeLists.txt | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fcd2c70b..acfc8eaf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ endforeach() # Force option if it applies if(PythonQt_Wrap_QtAll) - list(REMOVE_ITEM qtlibs xmlpatterns) # xmlpatterns wrapper does *NOT* build at all :( + list(REMOVE_ITEM qtlibs xmlpatterns) # xmlpatterns wrapper does *NOT* build at all :( foreach(qtlib ${qtlibs}) if(NOT ${PythonQt_Wrap_Qt${qtlib}}) set(PythonQt_Wrap_Qt${qtlib} ON CACHE BOOL "Make all of Qt${qtlib} available in python" FORCE) @@ -76,7 +76,7 @@ if(QT4_FOUND) if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version}) message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.") endif() - + # Enable required qt module foreach(qtlib network opengl sql svg uitools webkit xml xmlpatterns) string(TOUPPER ${qtlib} qtlib_uppercase) @@ -94,7 +94,7 @@ else() endif() #----------------------------------------------------------------------------- -# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers +# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers # associated with the Qt version being used. set(generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}") if("${generated_cpp_suffix}" STREQUAL "_46") @@ -123,7 +123,7 @@ set(sources src/PythonQtStdIn.cpp src/PythonQtStdOut.cpp src/gui/PythonQtScriptingConsole.cpp - + generated_cpp${generated_cpp_suffix}/PythonQt_QtBindings.cpp generated_cpp${generated_cpp_suffix}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.cpp @@ -178,27 +178,27 @@ set(moc_sources #----------------------------------------------------------------------------- # Add extra sources foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns) - + if (${PythonQt_Wrap_Qt${qtlib}}) - + ADD_DEFINITIONS(-DPYTHONQT_WRAP_Qt${qtlib}) - + set(file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qtlib}/com_trolltech_qt_${qtlib}) - + foreach(index RANGE 0 11) - + # Source files if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.cpp) list(APPEND sources ${file_prefix}${index}.cpp) endif() - + # Headers that should run through moc if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.h) list(APPEND moc_sources ${file_prefix}${index}.h) endif() - + endforeach() - + list(APPEND sources ${file_prefix}_init.cpp) endif() @@ -224,7 +224,7 @@ qt4_add_resources(gen_qrc_sources ${qrc_sources}) include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/src ) - + add_library(PythonQt SHARED ${sources} ${gen_moc_sources} @@ -276,10 +276,10 @@ if(BUILD_TESTING) ) set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain") - + add_executable(PythonQtCppTests ${test_sources}) target_link_libraries(PythonQtCppTests PythonQt) - + add_test( NAME tests_PythonQtTestMain COMMAND ${Slicer_LAUNCH_COMMAND} $ tests/PythonQtTestMain From 97ad91ae8aa7f884db010e2b41e2827f0c015b74 Mon Sep 17 00:00:00 2001 From: texpert Date: Thu, 7 May 2015 03:07:27 -0400 Subject: [PATCH 09/37] Fix unused variable warning in PythonQtSlot Co-authored-by: Jean-Christophe Fillion-Robin --- src/PythonQtSlot.cpp | 2 -- src/PythonQtStdIn.cpp | 1 + tests/PythonQtTests.cpp | 15 +++++++++++++++ tests/PythonQtTests.h | 16 +++++++++------- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/PythonQtSlot.cpp b/src/PythonQtSlot.cpp index 612a6670..ca594a55 100644 --- a/src/PythonQtSlot.cpp +++ b/src/PythonQtSlot.cpp @@ -86,7 +86,6 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj argList[0] = NULL; bool ok = true; - bool skipFirst = false; PythonQtPassThisOwnershipType passThisOwnership = IgnoreOwnership; int instanceDecoOffset = 0; @@ -94,7 +93,6 @@ bool PythonQtCallSlot(PythonQtClassInfo* classInfo, QObject* objectToCall, PyObj // would go away if it is moved into the if scope void* arg1 = NULL; if (info->isInstanceDecorator()) { - skipFirst = true; instanceDecoOffset = 1; // for decorators on CPP objects, we take the cpp ptr, for QObjects we take the QObject pointer diff --git a/src/PythonQtStdIn.cpp b/src/PythonQtStdIn.cpp index 7bf2c961..1311ad83 100644 --- a/src/PythonQtStdIn.cpp +++ b/src/PythonQtStdIn.cpp @@ -53,6 +53,7 @@ static PyObject *PythonQtStdInRedirect_new(PyTypeObject *type, PyObject * /*args static PyObject *PythonQtStdInRedirect_readline(PyObject * self, PyObject * args) { + Q_UNUSED(args); PythonQtStdInRedirect* s = (PythonQtStdInRedirect*)self; QString string; if (s->_cb) { diff --git a/tests/PythonQtTests.cpp b/tests/PythonQtTests.cpp index 65296604..801198dd 100644 --- a/tests/PythonQtTests.cpp +++ b/tests/PythonQtTests.cpp @@ -314,36 +314,46 @@ void PythonQtTestSlotCalling::testCppFactory() // PQCppObject2Decorator PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag1(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) { + Q_UNUSED(obj); return flag; } PQCppObject2::TestEnumFlag PQCppObject2Decorator::testEnumFlag2(PQCppObject2* obj, PQCppObject2::TestEnumFlag flag) { + Q_UNUSED(obj); return flag; } // with int overload PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, int flag) { + Q_UNUSED(obj); + Q_UNUSED(flag); return (TestEnumFlag)-1; } PQCppObject2Decorator::TestEnumFlag PQCppObject2Decorator::testEnumFlag3(PQCppObject2* obj, PQCppObject2Decorator::TestEnumFlag flag) { + Q_UNUSED(obj); return flag; } // PQCppObjectQFlagOnlyDecorator PQCppObjectQFlagOnlyDecorator::TestEnumFlag PQCppObjectQFlagOnlyDecorator::testEnumFlag1(PQCppObjectQFlagOnly* obj, PQCppObjectQFlagOnlyDecorator::TestEnumFlag flag) { + Q_UNUSED(obj); return flag; } PQCppObjectQFlagOnly::TestEnumFlag PQCppObjectQFlagOnlyDecorator::testEnumFlag2(PQCppObjectQFlagOnly* obj, PQCppObjectQFlagOnly::TestEnumFlag flag) { + Q_UNUSED(obj); return flag; } // with int overload PQCppObjectQFlagOnlyDecorator::TestEnumFlag PQCppObjectQFlagOnlyDecorator::testEnumFlag3(PQCppObjectQFlagOnly* obj, int flag) { + Q_UNUSED(obj); + Q_UNUSED(flag); return (TestEnumFlag)-1; } PQCppObjectQFlagOnlyDecorator::TestEnumFlag PQCppObjectQFlagOnlyDecorator::testEnumFlag3(PQCppObjectQFlagOnly* obj, PQCppObjectQFlagOnlyDecorator::TestEnumFlag flag) { + Q_UNUSED(obj); return flag; } @@ -618,12 +628,14 @@ void PythonQtTestApi::testQColorDecorators() QByteArray PythonQtTestApiHelper::readFileAsBytes(const QString& filename) { + Q_UNUSED(filename); QByteArray b; return b; } QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& ok) { + Q_UNUSED(filename); QByteArray b; ok = true; return b; @@ -631,10 +643,12 @@ QByteArray PythonQtTestApiHelper::readSourceFile(const QString& filename, bool& bool PythonQtTestApiHelper::exists(const QString& filename) { + Q_UNUSED(filename); return true; } QDateTime PythonQtTestApiHelper::lastModifiedDate(const QString& filename) { + Q_UNUSED(filename); return QDateTime::currentDateTime(); } @@ -658,6 +672,7 @@ void PythonQtTestApiHelper::stdErr(const QString& s) QObject* PythonQtTestCppFactory::create(const QByteArray& name, void *ptr) { + Q_UNUSED(name); if (name == "PQCppObject") { return new PQCppObjectWrapper(ptr); } diff --git a/tests/PythonQtTests.h b/tests/PythonQtTests.h index 3f06807d..c273432a 100644 --- a/tests/PythonQtTests.h +++ b/tests/PythonQtTests.h @@ -240,9 +240,11 @@ public Q_SLOTS: return new PQCppObjectNoWrap(0); } PQCppObjectNoWrap* new_PQCppObjectNoWrap(const PQCppObjectNoWrap& other) { + Q_UNUSED(other); return new PQCppObjectNoWrap(1); } PQCppObjectNoWrap* new_PQCppObjectNoWrap(double value) { + Q_UNUSED(value); return new PQCppObjectNoWrap(2); } @@ -429,13 +431,13 @@ public Q_SLOTS: void testNoArg() { _called = true; } //! overload test! - void overload(bool a) { _calledOverload = 0; _called = true; } - void overload(float a) { _calledOverload = 1; _called = true;} - void overload(int a) { _calledOverload = 2; _called = true;} - void overload(const QString& str) { _calledOverload = 3; _called = true;} - void overload(const QStringList& str) { _calledOverload = 4; _called = true;} - void overload(QObject* str) { _calledOverload = 5; _called = true;} - void overload(float a, int b) { _calledOverload = 6; _called = true;} + void overload(bool a) { Q_UNUSED(a); _calledOverload = 0; _called = true; } + void overload(float a) { Q_UNUSED(a); _calledOverload = 1; _called = true;} + void overload(int a) { Q_UNUSED(a); _calledOverload = 2; _called = true;} + void overload(const QString& str) { Q_UNUSED(str); _calledOverload = 3; _called = true;} + void overload(const QStringList& str) { Q_UNUSED(str); _calledOverload = 4; _called = true;} + void overload(QObject* str) { Q_UNUSED(str); _calledOverload = 5; _called = true;} + void overload(float a, int b) { Q_UNUSED(a); Q_UNUSED(b);_calledOverload = 6; _called = true;} //! POD values: int getInt(int a) { _called = true; return a; } From ff506f73386c312b69e013fdd5f5e7e1f25553f3 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sun, 10 May 2015 01:28:20 -0400 Subject: [PATCH 10/37] Ensure "PythonQtUtils.h" is installed when building using CMake The file "PythonQtUtils.h" has been added in r251 (started qt5 port) --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index acfc8eaf..3d3e378a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -157,6 +157,7 @@ set(headers src/PythonQtStdIn.h src/PythonQtStdOut.h src/PythonQtSystem.h + src/PythonQtUtils.h src/PythonQtVariants.h src/PythonQtPythonInclude.h generated_cpp${generated_cpp_suffix}/PythonQt_QtBindings.h From 5d1b5cad853e6933e111abf65861c4a23f7dae74 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 31 Aug 2015 11:28:32 -0400 Subject: [PATCH 11/37] Update README.md to describe the "patched-5" branch --- README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e43ea73..841026d3 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,17 @@ Additional configure options are: Available branches ------------------ -This repository contains three branches: -* Based on [r245](http://sourceforge.net/p/pythonqt/code/245/) +This repository contains 5 branches: + +### patched-5 +* Based on patched-4 + [r395](http://sourceforge.net/p/pythonqt/code/395/) +* List of features: + * CMake: + * Fix install rules + * Fix "_invalid_parameter_noinfo_noreturn" link error + * PythonQt: + * Add Qt5 support + * Add PY3K support ### patched-4 * Based on patched-3 + [r245](http://sourceforge.net/p/pythonqt/code/245/) From db06a1609bf7d3f28b05d0c634d9792814f551ca Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 31 Aug 2015 11:33:28 -0400 Subject: [PATCH 12/37] Update README.md to describe the "patched-6" branch --- README.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 841026d3..a06d6ca2 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,23 @@ Additional configure options are: Available branches ------------------ -This repository contains 5 branches: +This repository contains 6 branches: + +### patched-6 +* Based on patched-5 + [r403](http://sourceforge.net/p/pythonqt/code/403/) +* Includes the following PythonQt updates: +``` +$ git shortlog 2d445d5..e93e36b --no-merges +florianlink (8): + fixed error handling for evalFile made name->objectName alias optional (off by default, add PYTHONQT_SUPPORT_NAME_PROPERTY to DEFINES if you need it) added py_delete() slot support for built-in delete() method + added support for QTimer::singleShot() + fixed a missign QMetaObject::disconnect which leads to connection leaking added removeSignalHandlers() + fixed test + initial version that handles qualified virtual calls better + improved handling of qualified virtual calls + improved handling of qualified virtual calls + removed generating wrappers for virtual functions that are already declared in a base class +``` ### patched-5 * Based on patched-4 + [r395](http://sourceforge.net/p/pythonqt/code/395/) From ae54223cd6ed8a94eb0f9c673f5f7aad4574666e Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Fri, 28 Aug 2015 14:16:08 -0400 Subject: [PATCH 13/37] Add missing refcount decrements when creating wrappers PyObject_GetAttrString returns a new reference. PyDict_SetItemString does not steal a reference, so Py_DECREF should be called after PyDict_SetItemString. --- src/PythonQt.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index fa09e0d3..63c1d15e 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -708,6 +708,7 @@ PythonQtClassWrapper* PythonQtPrivate::createNewPythonQtClassWrapper(PythonQtCla // create the new type object by calling the type result = (PythonQtClassWrapper *)PyObject_Call((PyObject *)&PythonQtClassWrapper_Type, args, NULL); + Py_DECREF(moduleName); Py_DECREF(baseClasses); Py_DECREF(typeDict); Py_DECREF(args); @@ -741,6 +742,7 @@ PyObject* PythonQtPrivate::createNewPythonQtEnumWrapper(const char* enumName, Py // create the new int derived type object by calling the core type result = PyObject_Call((PyObject *)&PyType_Type, args, NULL); + Py_DECREF(module); Py_DECREF(baseClasses); Py_DECREF(typeDict); Py_DECREF(args); From ef6a1f247096c45333f7c05060c2888688bcc592 Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Mon, 31 Aug 2015 13:46:21 -0400 Subject: [PATCH 14/37] Fix refcount of PyInt_Type when creating enum wrapper This commit increments the refcount of the built-in PyInt_Type instance when creating an enum wrapper. This is necessary because PyTuple_SET_ITEM steals a reference to that instance. Fixing the refcount prevents a crash when calling Py_Finalize(). --- src/PythonQt.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 63c1d15e..ec334292 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -731,6 +731,7 @@ PyObject* PythonQtPrivate::createNewPythonQtEnumWrapper(const char* enumName, Py PyObject* className = PyString_FromString(enumName); PyObject* baseClasses = PyTuple_New(1); + Py_INCREF(&PyInt_Type); PyTuple_SET_ITEM(baseClasses, 0, (PyObject*)&PyInt_Type); PyObject* module = PyObject_GetAttrString(parentObject, "__module__"); From c3d8c8623d420454db0734b99d0a8062f39026e8 Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Fri, 28 Aug 2015 14:14:58 -0400 Subject: [PATCH 15/37] Prevent crash when an object is destroyed after calling PythonQt::cleanup() In certain situations the dealloc callback PythonQtInstanceWrapper_dealloc is called after PythonQt::cleanup() has been run. This can happen when Python destroys objects during Py_Finalize(). This commit adds a check that PythonQt is still initialized in the dealloc callback. --- src/PythonQtInstanceWrapper.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/PythonQtInstanceWrapper.cpp b/src/PythonQtInstanceWrapper.cpp index 3fa19b21..8fd3d8b6 100644 --- a/src/PythonQtInstanceWrapper.cpp +++ b/src/PythonQtInstanceWrapper.cpp @@ -119,7 +119,9 @@ static void PythonQtInstanceWrapper_deleteObject(PythonQtInstanceWrapper* self, static void PythonQtInstanceWrapper_dealloc(PythonQtInstanceWrapper* self) { - PythonQtInstanceWrapper_deleteObject(self); + if (PythonQt::self()) { + PythonQtInstanceWrapper_deleteObject(self); + } self->_obj.~QPointer(); Py_TYPE(self)->tp_free((PyObject*)self); } From e403085345b36b06cf45c8cbeeb192b88e57c76a Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 31 Aug 2015 16:36:30 -0400 Subject: [PATCH 16/37] Update README.md to include description of recent fixes --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index a06d6ca2..f9fbde69 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,8 @@ This repository contains 6 branches: ### patched-6 * Based on patched-5 + [r403](http://sourceforge.net/p/pythonqt/code/403/) +* List of bug fixes: + * Fix for memory leaks and cleanup crash * Includes the following PythonQt updates: ``` $ git shortlog 2d445d5..e93e36b --no-merges From 293674680e5cf256d25b8a29525a895ad975c1f5 Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Tue, 1 Sep 2015 09:20:57 -0400 Subject: [PATCH 17/37] Enable "name" property support Prior to commit https://github.com/commontk/PythonQt/commit/9c2e489d734758cd63bb7cbe4a0ed6ae6c6ce228, the "name" property was offered as an alias for the "objectName" property. Now, the alias is a compile-time option that is disabled by default. This commit enables the "name" property alias to maintain backwards compatibility with earlier versions. --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d3e378a..521129d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,10 @@ project(PythonQt) find_package(PythonLibs REQUIRED) include_directories("${PYTHON_INCLUDE_DIR}") -add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK) +add_definitions( + -DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK + -DPYTHONQT_SUPPORT_NAME_PROPERTY + ) #----------------------------------------------------------------------------- # Build options From 05624586fa7bc43b98f86c28b8dee7d39be5c0b6 Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Fri, 4 Sep 2015 15:36:00 -0400 Subject: [PATCH 18/37] Update README.md to describe new commits --- README.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f9fbde69..94b7b367 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Prerequisites Build instructions ------------------ -By default, the `patched-3` version will be checked out. +By default, the `patched-5` version will be checked out. ``` git clone git://github.com/commontk/PythonQt.git @@ -64,7 +64,9 @@ florianlink (8): ``` ### patched-5 -* Based on patched-4 + [r395](http://sourceforge.net/p/pythonqt/code/395/) +* Based on patched-4 + [r403](http://sourceforge.net/p/pythonqt/code/403/) excluding commit [r397](http://sourceforge.net/p/pythonqt/code/397/) +* List of bug fixes: + * Fix for memory leaks and cleanup crash * List of features: * CMake: * Fix install rules From a08c2d03bf60ebc6c622ce5dec6ee6315fa40ba4 Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Fri, 11 Sep 2015 09:17:59 -0400 Subject: [PATCH 19/37] Prevent crashes during and after cleanup This commit prevents crashes by handling scenarios such as: (a) object destruction after the Python interpreter has been finalized (b) object destruction after cleanup, i.e. the singleton no longer exists Any usage of a Qt enum demonstrates (a). One example that demonstrates (b) is a QTimer object which is created with a QApplication parent. PythonQt::cleanup() is called before the QApplication is completely destroyed, so the code that handles wrapping the QTimer object must handle the case when the PythonQt singleton no longer exists. Co-authored-by: Jean-Christophe Fillion-Robin --- src/PythonQt.h | 2 +- src/PythonQtObjectPtr.cpp | 2 +- src/PythonQtSignalReceiver.cpp | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/PythonQt.h b/src/PythonQt.h index 5a385936..9171011f 100644 --- a/src/PythonQt.h +++ b/src/PythonQt.h @@ -526,7 +526,7 @@ class PYTHONQT_EXPORT PythonQt : public QObject { //@{ //! get access to internal data (should not be used on the public API, but is used by some C functions) - static PythonQtPrivate* priv() { return _self->_p; } + static PythonQtPrivate* priv() { return _self ? _self->_p : NULL; } //! clear all NotFound entries on all class infos, to ensure that //! newly loaded wrappers can add methods even when the object was wrapped by PythonQt before the wrapper was loaded diff --git a/src/PythonQtObjectPtr.cpp b/src/PythonQtObjectPtr.cpp index 95fb4e0f..2d79a5bb 100644 --- a/src/PythonQtObjectPtr.cpp +++ b/src/PythonQtObjectPtr.cpp @@ -49,7 +49,7 @@ PythonQtObjectPtr::PythonQtObjectPtr(PyObject* o) PythonQtObjectPtr::~PythonQtObjectPtr() { - if (_object) Py_DECREF(_object); + if (_object && Py_IsInitialized()) Py_DECREF(_object); } void PythonQtObjectPtr::setNewRef(PyObject* o) diff --git a/src/PythonQtSignalReceiver.cpp b/src/PythonQtSignalReceiver.cpp index fda77da9..54341657 100644 --- a/src/PythonQtSignalReceiver.cpp +++ b/src/PythonQtSignalReceiver.cpp @@ -177,7 +177,9 @@ PythonQtSignalReceiver::PythonQtSignalReceiver(QObject* obj):PythonQtSignalRecei PythonQtSignalReceiver::~PythonQtSignalReceiver() { - PythonQt::priv()->removeSignalEmitter(_obj); + if (PythonQt::priv()) { + PythonQt::priv()->removeSignalEmitter(_obj); + } } From 1176466f10486ca776bc212fdc5aaf589efa0fcb Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Fri, 11 Sep 2015 10:06:45 -0400 Subject: [PATCH 20/37] Fix tests link error on Windows This commit fixes a link error building PythonQtCppTests on Windows: 1>PythonQtCppTests.obj : error LNK2001: unresolved external symbol "int __cdecl tests_PythonQtTestMain(int,char * * const)" (?tests_PythonQtTestMain@@YAHHQEAPEAD@Z) 1>C:\temp\PythonQt-build\Debug\PythonQtCppTests.exe : fatal error LNK1120: 1 unresolved externals --- tests/PythonQtTestMain.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/PythonQtTestMain.cpp b/tests/PythonQtTestMain.cpp index 44f5bea6..303ac0d0 100644 --- a/tests/PythonQtTestMain.cpp +++ b/tests/PythonQtTestMain.cpp @@ -44,7 +44,7 @@ #include -int main( int argc, char **argv ) +int main(int argc, char *argv[]) { QApplication qapp(argc, argv); From 290a5fb7858eac3f66e7edcd1548829b89965519 Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Fri, 11 Sep 2015 16:23:24 -0400 Subject: [PATCH 21/37] Fix refcount problems seen when re-initializing Python after finalizing A sequence of calls like the following would crash in Python when reinitializing the interpreter the second time: PythonQt::init(0); ... Py_Finalize(); PythonQt::init(0); ... Py_Finalize(); --- src/PythonQt.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index ec334292..54c94c6c 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -695,6 +695,7 @@ PythonQtClassWrapper* PythonQtPrivate::createNewPythonQtClassWrapper(PythonQtCla PyObject* className = PyString_FromString(pythonClassName.constData()); PyObject* baseClasses = PyTuple_New(1); + Py_INCREF(&PythonQtInstanceWrapper_Type); PyTuple_SET_ITEM(baseClasses, 0, (PyObject*)&PythonQtInstanceWrapper_Type); PyObject* typeDict = PyDict_New(); @@ -1650,6 +1651,7 @@ void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQ #endif _p->_pythonQtModuleName = name; + Py_INCREF(&PythonQtBoolResult_Type); PyModule_AddObject(_p->pythonQtModule().object(), "BoolResult", (PyObject*)&PythonQtBoolResult_Type); PythonQtObjectPtr sys; sys.setNewRef(PyImport_ImportModule("sys")); @@ -1673,7 +1675,9 @@ void PythonQt::initPythonQtModule(bool redirectStdOut, const QByteArray& pythonQ Py_ssize_t old_size = PyTuple_Size(old_module_names); PyObject *module_names = PyTuple_New(old_size + 1); for (Py_ssize_t i = 0; i < old_size; i++) { - PyTuple_SetItem(module_names, i, PyTuple_GetItem(old_module_names, i)); + PyObject *item = PyTuple_GetItem(old_module_names, i); + Py_INCREF(item); + PyTuple_SetItem(module_names, i, item); } PyTuple_SetItem(module_names, old_size, PyString_FromString(name.constData())); PyModule_AddObject(sys.object(), "builtin_module_names", module_names); From 9437eb6c716fc5bbb7cfa1d8c3f63fbf20020e3c Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Fri, 11 Sep 2015 16:31:48 -0400 Subject: [PATCH 22/37] Explicitly initialize global storage containers This commit changes initialization of the global storage containers to be explicit instead of happening during static initialization. This makes the containers properly initialized if PythonQt is initialized and cleaned up more than once. The motivation for this change is to support testing cleanup and finalization. --- src/PythonQt.cpp | 4 ++++ src/PythonQtMisc.h | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 54c94c6c..4ded66cf 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -1333,6 +1333,10 @@ PythonQtPrivate::PythonQtPrivate() _hadError = false; _systemExitExceptionHandlerEnabled = false; _debugAPI = new PythonQtDebugAPI(this); + + PythonQtConv::global_valueStorage.init(); + PythonQtConv::global_ptrStorage.init(); + PythonQtConv::global_variantStorage.init(); } void PythonQtPrivate::setupSharedLibrarySuffixes() diff --git a/src/PythonQtMisc.h b/src/PythonQtMisc.h index 2c75c456..65b58878 100644 --- a/src/PythonQtMisc.h +++ b/src/PythonQtMisc.h @@ -76,12 +76,25 @@ template class PythonQtValueStorage PythonQtValueStorage() { _chunkIdx = 0; _chunkOffset = 0; + _currentChunk = NULL; + }; + + //! initialize memory + void init() { + assert(_currentChunk == NULL); + assert(_chunks.isEmpty()); + _chunkIdx = 0; + _chunkOffset = 0; _currentChunk = new T[chunkEntries]; _chunks.append(_currentChunk); - }; + } //! clear all memory void clear() { + _chunkIdx = 0; + _chunkOffset = 0; + _currentChunk = NULL; + T* chunk; Q_FOREACH(chunk, _chunks) { delete[]chunk; From 4d2c80b6feff51848199ea120f3556dfdbeceff8 Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Fri, 11 Sep 2015 16:36:51 -0400 Subject: [PATCH 23/37] Add cleanup/finalization tests Add tests that check for clean cleanup and finalization in different scenarios. Co-authored-by: Jean-Christophe Fillion-Robin Co-authored-by: Pat Marion --- CMakeLists.txt | 12 ++++++ tests/PythonQtTestCleanup.cpp | 69 +++++++++++++++++++++++++++++++++++ tests/PythonQtTestCleanup.h | 45 +++++++++++++++++++++++ tests/PythonQtTestMain.cpp | 8 ++++ 4 files changed, 134 insertions(+) create mode 100644 tests/PythonQtTestCleanup.cpp create mode 100644 tests/PythonQtTestCleanup.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 521129d4..2349303a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -279,6 +279,18 @@ if(BUILD_TESTING) tests/PythonQtTests.h ) + if(PythonQt_Wrap_Qtcore) + include_directories(generated_cpp${generated_cpp_suffix}) + + list(APPEND test_sources + tests/PythonQtTestCleanup.cpp + tests/PythonQtTestCleanup.h + ) + QT4_WRAP_CPP(test_sources + tests/PythonQtTestCleanup.h + ) + endif() + set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain") add_executable(PythonQtCppTests ${test_sources}) diff --git a/tests/PythonQtTestCleanup.cpp b/tests/PythonQtTestCleanup.cpp new file mode 100644 index 00000000..796c0eba --- /dev/null +++ b/tests/PythonQtTestCleanup.cpp @@ -0,0 +1,69 @@ +#include "PythonQtTestCleanup.h" +#include "PythonQt.h" +#include "PythonQt_QtBindings.h" + +void PythonQtTestCleanup::initTestCase() +{ +} + +void PythonQtTestCleanup::cleanupTestCase() +{ +} + +void PythonQtTestCleanup::init() +{ + // Initialize before each test + + PythonQt::init(PythonQt::IgnoreSiteModule); + PythonQt_init_QtBindings(); + + _helper = new PythonQtTestCleanupHelper(); + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + PythonQt::self()->addObject(main, "obj", _helper); +} + +void PythonQtTestCleanup::cleanup() +{ + // Finalize and cleanup after each test + + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + PythonQt::self()->removeVariable(main, "obj"); + delete _helper; + _helper = NULL; + + if (Py_IsInitialized()) { + Py_Finalize(); + } + + PythonQt::cleanup(); +} + +void PythonQtTestCleanup::testQtEnum() +{ + QVERIFY(_helper->runScript( + "import PythonQt.QtCore\n" \ + "x = PythonQt.QtCore.QFile.ReadOnly\n" \ + "obj.setPassed()" + )); +} + +void PythonQtTestCleanup::testCallQtMethodInDel() +{ + QVERIFY(_helper->runScript( + "import PythonQt.QtCore\n" \ + "class TimerWrapper(object):\n" \ + " def __init__(self):\n" \ + " self.timer = PythonQt.QtCore.QTimer()\n" \ + " def __del__(self):\n" \ + " self.timer.setSingleShot(True)\n" \ + "x = TimerWrapper()\n" \ + "obj.setPassed()\n" + )); +} + +bool PythonQtTestCleanupHelper::runScript(const char* script) +{ + _passed = false; + PyRun_SimpleString(script); + return _passed; +} diff --git a/tests/PythonQtTestCleanup.h b/tests/PythonQtTestCleanup.h new file mode 100644 index 00000000..2c4879e2 --- /dev/null +++ b/tests/PythonQtTestCleanup.h @@ -0,0 +1,45 @@ +#ifndef _PYTHONQTTESTCLEANUP_H +#define _PYTHONQTTESTCLEANUP_H + +#include "PythonQt.h" +#include + +class PythonQtTestCleanupHelper; + +//! Test PythonQt cleanup and Python interpreter finalization +class PythonQtTestCleanup : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase(); + void cleanupTestCase(); + void init(); + void cleanup(); + + void testQtEnum(); + void testCallQtMethodInDel(); + +private: + PythonQtTestCleanupHelper* _helper; +}; + +//! Test helper class +class PythonQtTestCleanupHelper : public QObject +{ + Q_OBJECT +public: + PythonQtTestCleanupHelper() : + _passed(false) { + }; + + bool runScript(const char* script); + +public Q_SLOTS: + void setPassed() { _passed = true; } + +private: + bool _passed; +}; + +#endif diff --git a/tests/PythonQtTestMain.cpp b/tests/PythonQtTestMain.cpp index 303ac0d0..ac3a37d8 100644 --- a/tests/PythonQtTestMain.cpp +++ b/tests/PythonQtTestMain.cpp @@ -41,6 +41,7 @@ #include "PythonQt.h" #include "PythonQtTests.h" +#include "PythonQtTestCleanup.h" #include @@ -60,6 +61,13 @@ int main(int argc, char *argv[]) PythonQt::cleanup(); + if (Py_IsInitialized()) { + Py_Finalize(); + } + + PythonQtTestCleanup cleanup; + failCount += QTest::qExec(&cleanup, argc, argv); + if (failCount>0) { std::cerr << "Tests failed: " << failCount << std::endl; } else { From 4d36f864157222ded68411760f1e97b43ec91e72 Mon Sep 17 00:00:00 2001 From: Max Smolens Date: Tue, 15 Sep 2015 15:45:30 -0400 Subject: [PATCH 24/37] Fix PythonQtSignalReceiver crash during cleanup This commit fixes a crash during PythonQt::cleanup(). While destroying the PythonQtPrivate instance, any remaining PythonQtSignalReceivers that are kept alive only by their parent object will be destroyed. The crash occurs when PythonQtSignalReceiver's destructor calls back into PythonQtPrivate::removeSignalEmitter() when the PythonQtPrivate instance is mostly destroyed. Includes test case that crashes without the fix. --- src/PythonQt.cpp | 4 ++++ tests/PythonQtTestCleanup.cpp | 21 ++++++++++++++++----- tests/PythonQtTestCleanup.h | 2 ++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 4ded66cf..019b3fb8 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -274,6 +274,10 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName) void PythonQt::cleanup() { if (_self) { + // Remove signal handlers in advance, since destroying them calls back into + // PythonQt::priv()->removeSignalEmitter() + _self->removeSignalHandlers(); + delete _self; _self = NULL; } diff --git a/tests/PythonQtTestCleanup.cpp b/tests/PythonQtTestCleanup.cpp index 796c0eba..b60c7023 100644 --- a/tests/PythonQtTestCleanup.cpp +++ b/tests/PythonQtTestCleanup.cpp @@ -26,16 +26,14 @@ void PythonQtTestCleanup::cleanup() { // Finalize and cleanup after each test - PythonQtObjectPtr main = PythonQt::self()->getMainModule(); - PythonQt::self()->removeVariable(main, "obj"); - delete _helper; - _helper = NULL; - if (Py_IsInitialized()) { Py_Finalize(); } PythonQt::cleanup(); + + delete _helper; + _helper = NULL; } void PythonQtTestCleanup::testQtEnum() @@ -61,6 +59,19 @@ void PythonQtTestCleanup::testCallQtMethodInDel() )); } +void PythonQtTestCleanup::testSignalReceiverCleanup() +{ + PythonQtObjectPtr main = PythonQt::self()->getMainModule(); + + // Test that PythonQtSignalReceiver is cleaned up properly, + // i.e. PythonQt::cleanup() doesn't segfault + main.evalScript( + "import PythonQt.QtCore\n" \ + "timer = PythonQt.QtCore.QTimer(obj)\n" \ + "timer.connect('destroyed()', obj.onDestroyed)\n" \ + ); +} + bool PythonQtTestCleanupHelper::runScript(const char* script) { _passed = false; diff --git a/tests/PythonQtTestCleanup.h b/tests/PythonQtTestCleanup.h index 2c4879e2..b2a15886 100644 --- a/tests/PythonQtTestCleanup.h +++ b/tests/PythonQtTestCleanup.h @@ -19,6 +19,7 @@ private Q_SLOTS: void testQtEnum(); void testCallQtMethodInDel(); + void testSignalReceiverCleanup(); private: PythonQtTestCleanupHelper* _helper; @@ -37,6 +38,7 @@ class PythonQtTestCleanupHelper : public QObject public Q_SLOTS: void setPassed() { _passed = true; } + void onDestroyed(QObject *) { } private: bool _passed; From 7d181144338af85855b1b868222c2efbc75b80bb Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Tue, 16 Feb 2016 02:49:35 -0500 Subject: [PATCH 25/37] Fix compilation of test when PythonQt_Wrap_Qtcore option is disabled This commit fixes the following link error: PythonQtTestMain.cpp:(.text+0x1637): undefined reference to `PythonQtTestCleanup::~PythonQtTestCleanup()' --- CMakeLists.txt | 6 ++++-- tests/PythonQtTestMain.cpp | 3 +++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2349303a..a68fe3eb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,6 +270,8 @@ if(BUILD_TESTING) tests/PythonQtTestMain.cpp ) + set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain") + list(APPEND test_sources tests/PythonQtTests.cpp tests/PythonQtTests.h @@ -289,9 +291,9 @@ if(BUILD_TESTING) QT4_WRAP_CPP(test_sources tests/PythonQtTestCleanup.h ) - endif() - set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain") + set_property(SOURCE tests/PythonQtTestMain.cpp APPEND PROPERTY COMPILE_DEFINITIONS "PythonQt_Wrap_Qtcore") + endif() add_executable(PythonQtCppTests ${test_sources}) target_link_libraries(PythonQtCppTests PythonQt) diff --git a/tests/PythonQtTestMain.cpp b/tests/PythonQtTestMain.cpp index ac3a37d8..8b498ab4 100644 --- a/tests/PythonQtTestMain.cpp +++ b/tests/PythonQtTestMain.cpp @@ -65,6 +65,7 @@ int main(int argc, char *argv[]) Py_Finalize(); } +#ifdef PythonQt_Wrap_Qtcore PythonQtTestCleanup cleanup; failCount += QTest::qExec(&cleanup, argc, argv); @@ -73,6 +74,8 @@ int main(int argc, char *argv[]) } else { std::cout << "All tests passed successfully." << std::endl; } +#endif + return failCount; } From 330a0ed6d44be3f3ae3062c18e3bcb1e136d6fd4 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 18 Feb 2016 03:30:06 -0500 Subject: [PATCH 26/37] Remove unused call to qt4_wrap_ui/qt4_add_resources associated with PythonQt library --- CMakeLists.txt | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a68fe3eb..347aee6d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -208,19 +208,9 @@ foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns) endif() endforeach() -#----------------------------------------------------------------------------- -# UI files -set(ui_sources ) - -#----------------------------------------------------------------------------- -# Resources -set(qrc_sources ) - #----------------------------------------------------------------------------- # Do wrapping qt4_wrap_cpp(gen_moc_sources ${moc_sources}) -qt4_wrap_ui(gen_ui_sources ${ui_sources}) -qt4_add_resources(gen_qrc_sources ${qrc_sources}) #----------------------------------------------------------------------------- # Build the library @@ -232,8 +222,6 @@ include_directories( add_library(PythonQt SHARED ${sources} ${gen_moc_sources} - ${gen_ui_sources} - ${gen_qrc_sources} ) set_target_properties(PythonQt PROPERTIES DEFINE_SYMBOL PYTHONQT_EXPORTS) From 9766873fd1dbd3c642512c85667eeb4831ea5742 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 18 Feb 2016 03:34:39 -0500 Subject: [PATCH 27/37] Add macro pythonqt_wrap_cpp removing the need for qt version specific macros --- CMakeLists.txt | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 347aee6d..9450cd17 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -96,6 +96,10 @@ else() message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable") endif() +macro(pythonqt_wrap_cpp) + qt4_wrap_cpp(${ARGV}) +endmacro() + #----------------------------------------------------------------------------- # The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers # associated with the Qt version being used. @@ -210,7 +214,7 @@ endforeach() #----------------------------------------------------------------------------- # Do wrapping -qt4_wrap_cpp(gen_moc_sources ${moc_sources}) +pythonqt_wrap_cpp(gen_moc_sources ${moc_sources}) #----------------------------------------------------------------------------- # Build the library @@ -265,7 +269,7 @@ if(BUILD_TESTING) tests/PythonQtTests.h ) - QT4_WRAP_CPP(test_sources + pythonqt_wrap_cpp(test_sources tests/PythonQtTests.h ) @@ -276,7 +280,7 @@ if(BUILD_TESTING) tests/PythonQtTestCleanup.cpp tests/PythonQtTestCleanup.h ) - QT4_WRAP_CPP(test_sources + pythonqt_wrap_cpp(test_sources tests/PythonQtTestCleanup.h ) From f09671f7c00d4cef5055fc71239f72464bd868d4 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 18 Feb 2016 04:10:10 -0500 Subject: [PATCH 28/37] Re-factor code introducing qt_wrapped_libs variable --- CMakeLists.txt | 36 ++++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9450cd17..fab3aa74 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,20 @@ cmake_minimum_required(VERSION 2.8) project(PythonQt) #----------------------------------------------------------------------------- +#---------------------------------------------------------------------------- +# Qt version + +# Set PythonQt_QT_VERSION +set(PythonQt_QT_VERSION 4) + +# Requirements +set(minimum_required_qt4_version "4.6.2") +set(minimum_required_qt_version ${minimum_required_qt${PythonQt_QT_VERSION}_version}) + +# Qt components +set(qt4libs core gui network opengl sql svg uitools webkit xml xmlpatterns) +set(qtlibs ${qt${PythonQt_QT_VERSION}libs}) + #----------------------------------------------------------------------------- # Python libraries @@ -40,17 +54,24 @@ if(NOT DEFINED PythonQt_INSTALL_INCLUDE_DIR) set(PythonQt_INSTALL_INCLUDE_DIR include/PythonQt) endif() -option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF) +set(qt4_wrapped_libs ${qt4libs}) +set(qt_wrapped_libs ${qt${PythonQt_QT_VERSION}_wrapped_libs}) -set(qtlibs core gui network opengl sql svg uitools webkit xml xmlpatterns) -foreach(qtlib ${qtlibs}) +# Define PythonQt_Wrap_Qt* options +option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF) +foreach(qtlib ${qt_wrapped_libs}) OPTION(PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF) endforeach() + # Force option if it applies if(PythonQt_Wrap_QtAll) - list(REMOVE_ITEM qtlibs xmlpatterns) # xmlpatterns wrapper does *NOT* build at all :( - foreach(qtlib ${qtlibs}) + set(_qt_wrapped_libs ${qt_wrapped_libs}) + + # XXX xmlpatterns wrapper does *NOT* build at all :( + list(REMOVE_ITEM _qt_wrapped_libs xmlpatterns) + + foreach(qtlib ${_qt_wrapped_libs}) if(NOT ${PythonQt_Wrap_Qt${qtlib}}) set(PythonQt_Wrap_Qt${qtlib} ON CACHE BOOL "Make all of Qt${qtlib} available in python" FORCE) message(STATUS "Enabling [PythonQt_Wrap_Qt${qtlib}] because of [PythonQt_Wrap_QtAll] evaluates to True") @@ -68,7 +89,6 @@ endif() #----------------------------------------------------------------------------- # Setup Qt -set(minimum_required_qt_version "4.6.2") find_package(Qt4) @@ -81,7 +101,7 @@ if(QT4_FOUND) endif() # Enable required qt module - foreach(qtlib network opengl sql svg uitools webkit xml xmlpatterns) + foreach(qtlib ${qt_wrapped_libs}) string(TOUPPER ${qtlib} qtlib_uppercase) if (NOT ${QT_QT${qtlib_uppercase}_FOUND}) message(FATAL_ERROR "QT_QT${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}") @@ -185,7 +205,7 @@ set(moc_sources #----------------------------------------------------------------------------- # Add extra sources -foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns) +foreach(qtlib ${qt_wrapped_libs}) if (${PythonQt_Wrap_Qt${qtlib}}) From a49ec49eebec386b7dabbb763a3039a150fe1c61 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 18 Feb 2016 04:37:44 -0500 Subject: [PATCH 29/37] Refactor handling of "generated_cpp_suffix". This will allow to easily add new exceptions when adding support for Qt5.. --- CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index fab3aa74..ba2e1388 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -123,9 +123,12 @@ endmacro() #----------------------------------------------------------------------------- # The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers # associated with the Qt version being used. + +set(generated_cpp_suffix_46 _47) + set(generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}") -if("${generated_cpp_suffix}" STREQUAL "_46") - set(generated_cpp_suffix "_47") # Also use 4.7 wrappers for 4.6.x version +if(DEFINED generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}) + set(generated_cpp_suffix "${generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}}") endif() #----------------------------------------------------------------------------- From 82ebfa2728360a333280d719c60f71d5f6a6630d Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Thu, 18 Feb 2016 04:49:16 -0500 Subject: [PATCH 30/37] Add support for Qt5 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Based on work from the following individual: * Melven Röhrig-Zöllner (https://sourceforge.net/p/pythonqt/discussion/631392/thread/5f20c176/) * Julien Finet (@finetjul): See #38) * Arnaud Barre (@alzathar):See #15 * Eric Heim (@eric-h):See #36 --- CMakeLists.txt | 122 ++++++++++++++++++----- generated_cpp_50/PythonQt_QtBindings.cpp | 58 +++++++++++ generated_cpp_50/PythonQt_QtBindings.h | 10 ++ generated_cpp_53/PythonQt_QtBindings.cpp | 58 +++++++++++ generated_cpp_53/PythonQt_QtBindings.h | 10 ++ generated_cpp_54/PythonQt_QtBindings.cpp | 58 +++++++++++ generated_cpp_54/PythonQt_QtBindings.h | 10 ++ 7 files changed, 303 insertions(+), 23 deletions(-) create mode 100644 generated_cpp_50/PythonQt_QtBindings.cpp create mode 100644 generated_cpp_50/PythonQt_QtBindings.h create mode 100644 generated_cpp_53/PythonQt_QtBindings.cpp create mode 100644 generated_cpp_53/PythonQt_QtBindings.h create mode 100644 generated_cpp_54/PythonQt_QtBindings.cpp create mode 100644 generated_cpp_54/PythonQt_QtBindings.h diff --git a/CMakeLists.txt b/CMakeLists.txt index ba2e1388..0d1deb31 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,14 +14,33 @@ project(PythonQt) #---------------------------------------------------------------------------- # Qt version +# Sanity checks +if(DEFINED Qt5_DIR AND DEFINED QT_QMAKE_EXECUTABLE) + message(FATAL_ERROR + "${PROJECT_NAME} shoult NOT be configured setting both Qt5_DIR and QT_QMAKE_EXECUTABLE options. +To build with Qt4, specify QT_QMAKE_EXECUTABLE. To build with Qt5, specify Qt5_DIR.") +endif() + # Set PythonQt_QT_VERSION -set(PythonQt_QT_VERSION 4) +if(DEFINED Qt5_DIR) + message(STATUS "${PROJECT_NAME}: Setting PythonQt_QT_VERSION to 5 because Qt5_DIR is defined.") + set(PythonQt_QT_VERSION 5) +elseif(DEFINED QT_QMAKE_EXECUTABLE) + message(STATUS "${PROJECT_NAME}: Setting PythonQt_QT_VERSION to 4 because QT_QMAKE_EXECUTABLE is defined.") + set(PythonQt_QT_VERSION 4) +else() + set(PythonQt_QT_VERSION 4 CACHE STRING "Pick a version of Qt to use: 4 or 5") + # Set the possible values of Qt version for cmake-gui + set_property(CACHE PythonQt_QT_VERSION PROPERTY STRINGS "4" "5") +endif() # Requirements +set(minimum_required_qt5_version "5.3.0") set(minimum_required_qt4_version "4.6.2") set(minimum_required_qt_version ${minimum_required_qt${PythonQt_QT_VERSION}_version}) # Qt components +set(qt5libs Core Widgets Network OpenGL Sql Svg UiTools WebKitWidgets Xml XmlPatterns) set(qt4libs core gui network opengl sql svg uitools webkit xml xmlpatterns) set(qtlibs ${qt${PythonQt_QT_VERSION}libs}) @@ -54,15 +73,32 @@ if(NOT DEFINED PythonQt_INSTALL_INCLUDE_DIR) set(PythonQt_INSTALL_INCLUDE_DIR include/PythonQt) endif() +# Since the Qt bindings sources used for both Qt4 and Qt5 are +# grouped using Qt4 naming convention, qt_wrapped_libs variables are the +# same for the two Qt versions. set(qt4_wrapped_libs ${qt4libs}) +set(qt5_wrapped_libs ${qt4libs}) set(qt_wrapped_libs ${qt${PythonQt_QT_VERSION}_wrapped_libs}) +set(qt5_wrapped_lib_depends_gui Multimedia) + +set(qtlib_to_wraplib_Widgets gui) +set(qtlib_to_wraplib_WebKitWidgets webkit) + # Define PythonQt_Wrap_Qt* options option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF) foreach(qtlib ${qt_wrapped_libs}) OPTION(PythonQt_Wrap_Qt${qtlib} "Make all of Qt${qtlib} available in python" OFF) endforeach() +# Set qtlib_to_wraplib_* variables +foreach(qtlib ${qtlibs}) + string(TOLOWER ${qtlib} qtlib_lowercase) + if(DEFINED qtlib_to_wraplib_${qtlib}) + set(qtlib_lowercase ${qtlib_to_wraplib_${qtlib}}) + endif() + set(qtlib_to_wraplib_${qtlib} ${qtlib_lowercase}) +endforeach() # Force option if it applies if(PythonQt_Wrap_QtAll) @@ -89,46 +125,86 @@ endif() #----------------------------------------------------------------------------- # Setup Qt +if(PythonQt_QT_VERSION VERSION_GREATER "4") -find_package(Qt4) + # Required components + set(qt_required_components Core Widgets) + foreach(qtlib ${qtlibs}) + set(qt_wrapped_lib ${qtlib_to_wraplib_${qtlib}}) + if(${PythonQt_Wrap_Qt${qt_wrapped_lib}}) + list(APPEND qt_required_components ${qtlib} ${qt${PythonQt_QT_VERSION}_wrapped_lib_depends_${qt_wrapped_lib}}) + endif() + endforeach() + if(BUILD_TESTING) + list(APPEND qt_required_components Test) + endif() + list(REMOVE_DUPLICATES qt_required_components) -if(QT4_FOUND) + message(STATUS "${PROJECT_NAME}: Required Qt components [${qt_required_components}]") + find_package(Qt5 ${minimum_required_qt_version} COMPONENTS ${qt_required_components} REQUIRED) - set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}) + set(QT_LIBRARIES ) + foreach(qtlib ${qt_required_components}) + include_directories(${Qt5${qtlib}_INCLUDE_DIRS}) + add_definitions(${Qt5${qtlib}_DEFINITIONS}) + list(APPEND QT_LIBRARIES ${Qt5${qtlib}_LIBRARIES}) + endforeach() - if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version}) - message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.") - endif() + set(QT_VERSION_MAJOR ${Qt5Core_VERSION_MAJOR}) + set(QT_VERSION_MINOR ${Qt5Core_VERSION_MINOR}) + + macro(pythonqt_wrap_cpp) + qt5_wrap_cpp(${ARGV}) + endmacro() - # Enable required qt module - foreach(qtlib ${qt_wrapped_libs}) - string(TOUPPER ${qtlib} qtlib_uppercase) - if (NOT ${QT_QT${qtlib_uppercase}_FOUND}) - message(FATAL_ERROR "QT_QT${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}") +else() + + find_package(Qt4) + + if(QT4_FOUND) + + set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH}) + + if(${found_qt_version} VERSION_LESS ${minimum_required_qt_version}) + message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt_version} -- you cannot use Qt ${found_qt_version}.") endif() - set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}}) - endforeach() - set(QT_USE_QTTEST ${BUILD_TESTING}) + # Enable required qt module + foreach(qtlib ${qt_wrapped_libs}) + string(TOUPPER ${qtlib} qtlib_uppercase) + if (NOT ${QT_QT${qtlib_uppercase}_FOUND}) + message(FATAL_ERROR "QT_QT${qtlib_uppercase} *not* FOUND - Try to disable PythonQt_Wrap_Qt${qtlib}") + endif() + set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}}) + endforeach() - include(${QT_USE_FILE}) -else() - message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable") -endif() + # Enable QtTest in Qt4 is the option BUILD_TESTING was activated + set(QT_USE_QTTEST ${BUILD_TESTING}) -macro(pythonqt_wrap_cpp) - qt4_wrap_cpp(${ARGV}) -endmacro() + include(${QT_USE_FILE}) + else() + message(FATAL_ERROR "error: Qt4 was not found on your system. You probably need to set the QT_QMAKE_EXECUTABLE variable") + endif() + + macro(pythonqt_wrap_cpp) + qt4_wrap_cpp(${ARGV}) + endmacro() + +endif() #----------------------------------------------------------------------------- # The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers # associated with the Qt version being used. set(generated_cpp_suffix_46 _47) +set(generated_cpp_suffix_52 _50) +set(generated_cpp_suffix_51 _50) set(generated_cpp_suffix "_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}") if(DEFINED generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}) set(generated_cpp_suffix "${generated_cpp_suffix_${QT_VERSION_MAJOR}${QT_VERSION_MINOR}}") +elseif(${QT_VERSION_MAJOR}.${QT_VERSION_MINOR} VERSION_GREATER "5.4") + set(generated_cpp_suffix "_54") endif() #----------------------------------------------------------------------------- @@ -216,7 +292,7 @@ foreach(qtlib ${qt_wrapped_libs}) set(file_prefix generated_cpp${generated_cpp_suffix}/com_trolltech_qt_${qtlib}/com_trolltech_qt_${qtlib}) - foreach(index RANGE 0 11) + foreach(index RANGE 0 12) # Source files if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${file_prefix}${index}.cpp) diff --git a/generated_cpp_50/PythonQt_QtBindings.cpp b/generated_cpp_50/PythonQt_QtBindings.cpp new file mode 100644 index 00000000..7ae1630a --- /dev/null +++ b/generated_cpp_50/PythonQt_QtBindings.cpp @@ -0,0 +1,58 @@ + +#include "PythonQt_QtBindings.h" + +#include "PythonQt.h" + +void PythonQt_init_QtGui(PyObject*); +void PythonQt_init_QtSvg(PyObject*); +void PythonQt_init_QtSql(PyObject*); +void PythonQt_init_QtNetwork(PyObject*); +void PythonQt_init_QtCore(PyObject*); +void PythonQt_init_QtWebKit(PyObject*); +void PythonQt_init_QtOpenGL(PyObject*); +void PythonQt_init_QtXml(PyObject*); +void PythonQt_init_QtXmlPatterns(PyObject*); +void PythonQt_init_QtUiTools(PyObject*); + +PYTHONQT_EXPORT void PythonQt_init_QtBindings() + { + #ifdef PYTHONQT_WRAP_Qtcore + PythonQt_init_QtCore(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtgui + PythonQt_init_QtGui(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtnetwork + PythonQt_init_QtNetwork(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtopengl + PythonQt_init_QtOpenGL(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtsql + PythonQt_init_QtSql(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtsvg + PythonQt_init_QtSvg(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtuitools + PythonQt_init_QtUiTools(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtwebkit + PythonQt_init_QtWebKit(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtxml + PythonQt_init_QtXml(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtxmlpatterns + PythonQt_init_QtXmlPatterns(0); + #endif + }; diff --git a/generated_cpp_50/PythonQt_QtBindings.h b/generated_cpp_50/PythonQt_QtBindings.h new file mode 100644 index 00000000..03e96aed --- /dev/null +++ b/generated_cpp_50/PythonQt_QtBindings.h @@ -0,0 +1,10 @@ +#ifndef _PYTHONQT_QTBINDINGS_H +#define _PYTHONQT_QTBINDINGS_H + +#include "PythonQtSystem.h" + +/// Initialize Qt bindings enabled at configuration time +PYTHONQT_EXPORT void PythonQt_init_QtBindings(); + +#endif + diff --git a/generated_cpp_53/PythonQt_QtBindings.cpp b/generated_cpp_53/PythonQt_QtBindings.cpp new file mode 100644 index 00000000..7ae1630a --- /dev/null +++ b/generated_cpp_53/PythonQt_QtBindings.cpp @@ -0,0 +1,58 @@ + +#include "PythonQt_QtBindings.h" + +#include "PythonQt.h" + +void PythonQt_init_QtGui(PyObject*); +void PythonQt_init_QtSvg(PyObject*); +void PythonQt_init_QtSql(PyObject*); +void PythonQt_init_QtNetwork(PyObject*); +void PythonQt_init_QtCore(PyObject*); +void PythonQt_init_QtWebKit(PyObject*); +void PythonQt_init_QtOpenGL(PyObject*); +void PythonQt_init_QtXml(PyObject*); +void PythonQt_init_QtXmlPatterns(PyObject*); +void PythonQt_init_QtUiTools(PyObject*); + +PYTHONQT_EXPORT void PythonQt_init_QtBindings() + { + #ifdef PYTHONQT_WRAP_Qtcore + PythonQt_init_QtCore(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtgui + PythonQt_init_QtGui(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtnetwork + PythonQt_init_QtNetwork(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtopengl + PythonQt_init_QtOpenGL(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtsql + PythonQt_init_QtSql(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtsvg + PythonQt_init_QtSvg(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtuitools + PythonQt_init_QtUiTools(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtwebkit + PythonQt_init_QtWebKit(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtxml + PythonQt_init_QtXml(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtxmlpatterns + PythonQt_init_QtXmlPatterns(0); + #endif + }; diff --git a/generated_cpp_53/PythonQt_QtBindings.h b/generated_cpp_53/PythonQt_QtBindings.h new file mode 100644 index 00000000..03e96aed --- /dev/null +++ b/generated_cpp_53/PythonQt_QtBindings.h @@ -0,0 +1,10 @@ +#ifndef _PYTHONQT_QTBINDINGS_H +#define _PYTHONQT_QTBINDINGS_H + +#include "PythonQtSystem.h" + +/// Initialize Qt bindings enabled at configuration time +PYTHONQT_EXPORT void PythonQt_init_QtBindings(); + +#endif + diff --git a/generated_cpp_54/PythonQt_QtBindings.cpp b/generated_cpp_54/PythonQt_QtBindings.cpp new file mode 100644 index 00000000..7ae1630a --- /dev/null +++ b/generated_cpp_54/PythonQt_QtBindings.cpp @@ -0,0 +1,58 @@ + +#include "PythonQt_QtBindings.h" + +#include "PythonQt.h" + +void PythonQt_init_QtGui(PyObject*); +void PythonQt_init_QtSvg(PyObject*); +void PythonQt_init_QtSql(PyObject*); +void PythonQt_init_QtNetwork(PyObject*); +void PythonQt_init_QtCore(PyObject*); +void PythonQt_init_QtWebKit(PyObject*); +void PythonQt_init_QtOpenGL(PyObject*); +void PythonQt_init_QtXml(PyObject*); +void PythonQt_init_QtXmlPatterns(PyObject*); +void PythonQt_init_QtUiTools(PyObject*); + +PYTHONQT_EXPORT void PythonQt_init_QtBindings() + { + #ifdef PYTHONQT_WRAP_Qtcore + PythonQt_init_QtCore(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtgui + PythonQt_init_QtGui(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtnetwork + PythonQt_init_QtNetwork(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtopengl + PythonQt_init_QtOpenGL(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtsql + PythonQt_init_QtSql(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtsvg + PythonQt_init_QtSvg(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtuitools + PythonQt_init_QtUiTools(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtwebkit + PythonQt_init_QtWebKit(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtxml + PythonQt_init_QtXml(0); + #endif + + #ifdef PYTHONQT_WRAP_Qtxmlpatterns + PythonQt_init_QtXmlPatterns(0); + #endif + }; diff --git a/generated_cpp_54/PythonQt_QtBindings.h b/generated_cpp_54/PythonQt_QtBindings.h new file mode 100644 index 00000000..03e96aed --- /dev/null +++ b/generated_cpp_54/PythonQt_QtBindings.h @@ -0,0 +1,10 @@ +#ifndef _PYTHONQT_QTBINDINGS_H +#define _PYTHONQT_QTBINDINGS_H + +#include "PythonQtSystem.h" + +/// Initialize Qt bindings enabled at configuration time +PYTHONQT_EXPORT void PythonQt_init_QtBindings(); + +#endif + From 04b74f46779d271f5a99f422499a055715a033cc Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sat, 21 May 2016 15:30:32 -0400 Subject: [PATCH 31/37] addDecorators: Check for null object --- src/PythonQt.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PythonQt.cpp b/src/PythonQt.cpp index 019b3fb8..7b0020d7 100644 --- a/src/PythonQt.cpp +++ b/src/PythonQt.cpp @@ -1378,6 +1378,10 @@ PythonQtClassInfo* PythonQtPrivate::currentClassInfoForClassWrapperCreation() void PythonQtPrivate::addDecorators(QObject* o, int decoTypes) { + if (!o) + { + return; + } o->setParent(this); int numMethods = o->metaObject()->methodCount(); for (int i = 0; i < numMethods; i++) { From 50d646c065ae1117d89feacf997b14481c117974 Mon Sep 17 00:00:00 2001 From: Matthew Woehlke Date: Tue, 24 May 2016 16:29:47 -0400 Subject: [PATCH 32/37] Add missing link to OpenGL library --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d1deb31..57ab1fc0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,6 +192,12 @@ else() endif() +if(UNIX) + find_package(OpenGL) + if(OPENGL_FOUND) + list(APPEND QT_LIBRARIES ${OPENGL_LIBRARIES}) + endif() +endif() #----------------------------------------------------------------------------- # The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers # associated with the Qt version being used. From 1a8b9aeec9c8a0da1a84ad59435f1482cf790137 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Mon, 16 Jan 2017 22:19:29 -0500 Subject: [PATCH 33/37] Update README.md to describe the "patched-7" branch --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 94b7b367..c8dc5c2e 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,12 @@ Additional configure options are: Available branches ------------------ -This repository contains 6 branches: +This repository contains 7 branches: + +### patched-7 +* Based on [r443](http://sourceforge.net/p/pythonqt/code/443/) with: + * partial revert of [r431](http://sourceforge.net/p/pythonqt/code/431/) to re-enable CMake support + * all changes from ``patched-6`` cherry-picked. ### patched-6 * Based on patched-5 + [r403](http://sourceforge.net/p/pythonqt/code/403/) From 1cc9275efcc0e9645041fb1e8de6505754c702a8 Mon Sep 17 00:00:00 2001 From: Jean-Christophe Fillion-Robin Date: Sun, 11 Jun 2017 12:00:55 -0400 Subject: [PATCH 34/37] README.md: Fix formatting --- README.md | 66 +++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index c8dc5c2e..ad19c2da 100644 --- a/README.md +++ b/README.md @@ -47,13 +47,13 @@ This repository contains 7 branches: ### patched-7 * Based on [r443](http://sourceforge.net/p/pythonqt/code/443/) with: - * partial revert of [r431](http://sourceforge.net/p/pythonqt/code/431/) to re-enable CMake support - * all changes from ``patched-6`` cherry-picked. + * partial revert of [r431](http://sourceforge.net/p/pythonqt/code/431/) to re-enable CMake support + * all changes from ``patched-6`` cherry-picked. ### patched-6 * Based on patched-5 + [r403](http://sourceforge.net/p/pythonqt/code/403/) * List of bug fixes: - * Fix for memory leaks and cleanup crash + * Fix for memory leaks and cleanup crash * Includes the following PythonQt updates: ``` $ git shortlog 2d445d5..e93e36b --no-merges @@ -71,55 +71,55 @@ florianlink (8): ### patched-5 * Based on patched-4 + [r403](http://sourceforge.net/p/pythonqt/code/403/) excluding commit [r397](http://sourceforge.net/p/pythonqt/code/397/) * List of bug fixes: - * Fix for memory leaks and cleanup crash + * Fix for memory leaks and cleanup crash * List of features: - * CMake: - * Fix install rules - * Fix "_invalid_parameter_noinfo_noreturn" link error - * PythonQt: - * Add Qt5 support - * Add PY3K support + * CMake: + * Fix install rules + * Fix "_invalid_parameter_noinfo_noreturn" link error + * PythonQt: + * Add Qt5 support + * Add PY3K support ### patched-4 * Based on patched-3 + [r245](http://sourceforge.net/p/pythonqt/code/245/) * List of features: - * Add BUILD_TESTING option disabled by default to keep behavior consistent with previous version. - * Do not exclude enums from wrapping if they are QFlags. - * Ensure enums added using only Q_FLAGS without corresponding Q_ENUMS are wrapped. + * Add BUILD_TESTING option disabled by default to keep behavior consistent with previous version. + * Do not exclude enums from wrapping if they are QFlags. + * Ensure enums added using only Q_FLAGS without corresponding Q_ENUMS are wrapped. ### patched-3 * Backported: - * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/e2dce4b...patched-2) `patched-2` branch have been backported upstream: [r241](http://sourceforge.net/p/pythonqt/code/241/), [r242](http://sourceforge.net/p/pythonqt/code/242/), [r243](http://sourceforge.net/p/pythonqt/code/243/) + * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/e2dce4b...patched-2) `patched-2` branch have been backported upstream: [r241](http://sourceforge.net/p/pythonqt/code/241/), [r242](http://sourceforge.net/p/pythonqt/code/242/), [r243](http://sourceforge.net/p/pythonqt/code/243/) ### patched-2 * Based on [r228](http://sourceforge.net/p/pythonqt/code/228/) * List of features: - * At configuration time, detect the Qt version used and seamlessly compile the appropriate wrappers (Qt 4.8, 4.7 or 4.6). - * Add method allowing to know if a python error occurred: [5935f29](https://github.com/commontk/PythonQt/commit/5935f29978deed892a13ddef02cb14c205c6124d) - * Also add associated method "resetErrorFlag": [a386dc60](https://github.com/commontk/PythonQt/commit/a386dc60f71c15e67c611bc31b26cee756ed833a) - * Fix compilation issue on VS2010 when PythonQt Debug build against python Release: [7e1e07f](https://github.com/commontk/PythonQt/commit/7e1e07f34b2420e420e2858e5ea9a49fe1e0d235) - * Add option Add PythonQt_Wrap_QtAll: [97df3b0](https://github.com/commontk/PythonQt/commit/97df3b0845b3f5c987d3141a9e651436882f5913) and [9104fa9](https://github.com/commontk/PythonQt/commit/9104fa924859f4a865016f2138c06ec856f449d4) - * Ensure all 4.8 generated wrappers are considered: [654f324](https://github.com/commontk/PythonQt/commit/654f3249d1cf3f3ff674b2ff6cca7a2ef3517f60) - * Update "PythonQtPythonInclude.h" to avoid build error on recent MacOSX: [7b8ee130](https://github.com/commontk/PythonQt/commit/7b8ee13058bc0b366983ce8228612e75f8dd9ca8) and [47738f9c](https://github.com/commontk/PythonQt/commit/47738f9c8c5d3ffa77c8f2e1844f899e5b548f0c) - * Update "PythonQtPythonInclude.h" to fix windows build issue when PythonQt Debug build against python Release[6366f00](https://github.com/commontk/PythonQt/commit/6366f002a93aa238c55f58de949d09c552cda5a9) - * Optionally include CTestUseLaunchers: [211440](https://github.com/commontk/PythonQt/commit/2114405a47836b3fb16a3f66fec6a02184f32e71) - * Add SystemExit exception handler. If enabled, the signal "systemExitExceptionRaised" will be emitted. It gives application the opportunity to cleanup and terminate nicely: [3c84463d](https://github.com/commontk/PythonQt/commit/3c84463d3fc4a99c94207c1116ba33d7a412a95f) - * Add "isatty" function to StdOutRedirect. Needed by some logging frame: [7132dba9](https://github.com/commontk/PythonQt/commit/7132dba93064c2a02591b42305fecdd5d59702d3) + * At configuration time, detect the Qt version used and seamlessly compile the appropriate wrappers (Qt 4.8, 4.7 or 4.6). + * Add method allowing to know if a python error occurred: [5935f29](https://github.com/commontk/PythonQt/commit/5935f29978deed892a13ddef02cb14c205c6124d) + * Also add associated method "resetErrorFlag": [a386dc60](https://github.com/commontk/PythonQt/commit/a386dc60f71c15e67c611bc31b26cee756ed833a) + * Fix compilation issue on VS2010 when PythonQt Debug build against python Release: [7e1e07f](https://github.com/commontk/PythonQt/commit/7e1e07f34b2420e420e2858e5ea9a49fe1e0d235) + * Add option Add PythonQt_Wrap_QtAll: [97df3b0](https://github.com/commontk/PythonQt/commit/97df3b0845b3f5c987d3141a9e651436882f5913) and [9104fa9](https://github.com/commontk/PythonQt/commit/9104fa924859f4a865016f2138c06ec856f449d4) + * Ensure all 4.8 generated wrappers are considered: [654f324](https://github.com/commontk/PythonQt/commit/654f3249d1cf3f3ff674b2ff6cca7a2ef3517f60) + * Update "PythonQtPythonInclude.h" to avoid build error on recent MacOSX: [7b8ee130](https://github.com/commontk/PythonQt/commit/7b8ee13058bc0b366983ce8228612e75f8dd9ca8) and [47738f9c](https://github.com/commontk/PythonQt/commit/47738f9c8c5d3ffa77c8f2e1844f899e5b548f0c) + * Update "PythonQtPythonInclude.h" to fix windows build issue when PythonQt Debug build against python Release[6366f00](https://github.com/commontk/PythonQt/commit/6366f002a93aa238c55f58de949d09c552cda5a9) + * Optionally include CTestUseLaunchers: [211440](https://github.com/commontk/PythonQt/commit/2114405a47836b3fb16a3f66fec6a02184f32e71) + * Add SystemExit exception handler. If enabled, the signal "systemExitExceptionRaised" will be emitted. It gives application the opportunity to cleanup and terminate nicely: [3c84463d](https://github.com/commontk/PythonQt/commit/3c84463d3fc4a99c94207c1116ba33d7a412a95f) + * Add "isatty" function to StdOutRedirect. Needed by some logging frame: [7132dba9](https://github.com/commontk/PythonQt/commit/7132dba93064c2a02591b42305fecdd5d59702d3) * Backported: - * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/svn-mirror...patched) `patched` branch have been backported upstream: [r200](http://sourceforge.net/p/pythonqt/code/200/), [r201](http://sourceforge.net/p/pythonqt/code/201/), [r202](http://sourceforge.net/p/pythonqt/code/202/), [r203](http://sourceforge.net/p/pythonqt/code/203/), [r204](http://sourceforge.net/p/pythonqt/code/204/) - * CMake option `PYTHONQT_USE_VTK` has been removed ([r205](http://sourceforge.net/p/pythonqt/code/205/)), the foreign wrapper mechanism should be used: [r206](http://sourceforge.net/p/pythonqt/code/206/) + * Most of the [change specific to](https://github.com/commontk/PythonQt/compare/svn-mirror...patched) `patched` branch have been backported upstream: [r200](http://sourceforge.net/p/pythonqt/code/200/), [r201](http://sourceforge.net/p/pythonqt/code/201/), [r202](http://sourceforge.net/p/pythonqt/code/202/), [r203](http://sourceforge.net/p/pythonqt/code/203/), [r204](http://sourceforge.net/p/pythonqt/code/204/) + * CMake option `PYTHONQT_USE_VTK` has been removed ([r205](http://sourceforge.net/p/pythonqt/code/205/)), the foreign wrapper mechanism should be used: [r206](http://sourceforge.net/p/pythonqt/code/206/) ### patched * Based on [r193](http://sourceforge.net/p/pythonqt/code/193/) * List of features: - * CMake'ified PythonQt project - * CMake'ified PythonQt/generator project - * Add `dPython.h` file, it provides the ability to link against release python with a debug build of your project. - * Option `PYTHONQT_USE_VTK` CMake option allowing to teach PythonQt how to deal with `vtkObject` - * Stdin can optionally be redirected to a custom callback - * [More details](https://github.com/commontk/PythonQt/compare/svn-mirror...patched) + * CMake'ified PythonQt project + * CMake'ified PythonQt/generator project + * Add `dPython.h` file, it provides the ability to link against release python with a debug build of your project. + * Option `PYTHONQT_USE_VTK` CMake option allowing to teach PythonQt how to deal with `vtkObject` + * Stdin can optionally be redirected to a custom callback + * [More details](https://github.com/commontk/PythonQt/compare/svn-mirror...patched) ### svn-mirror From 57117bb3bb6d7e26cc2e1fea19023274319853c8 Mon Sep 17 00:00:00 2001 From: Christoph Willing Date: Sun, 11 Jun 2017 11:42:23 -0400 Subject: [PATCH 35/37] Revert "removed enums that have been removed in Qt 5.8" This reverts commit ce7e479ce82518c41c2a86f1c3acb150230311ec. --- .../com_trolltech_qt_core_builtin0.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generated_cpp_56/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.h b/generated_cpp_56/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.h index 66750cf3..015ed67f 100644 --- a/generated_cpp_56/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.h +++ b/generated_cpp_56/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin0.h @@ -1272,7 +1272,7 @@ enum WindowModality{ enum WindowState{ WindowNoState = Qt::WindowNoState, WindowMinimized = Qt::WindowMinimized, WindowMaximized = Qt::WindowMaximized, WindowFullScreen = Qt::WindowFullScreen, WindowActive = Qt::WindowActive}; enum WindowType{ - Widget = Qt::Widget, Window = Qt::Window, Dialog = Qt::Dialog, Sheet = Qt::Sheet, Drawer = Qt::Drawer, Popup = Qt::Popup, Tool = Qt::Tool, ToolTip = Qt::ToolTip, SplashScreen = Qt::SplashScreen, Desktop = Qt::Desktop, SubWindow = Qt::SubWindow, ForeignWindow = Qt::ForeignWindow, CoverWindow = Qt::CoverWindow, WindowType_Mask = Qt::WindowType_Mask, MSWindowsFixedSizeDialogHint = Qt::MSWindowsFixedSizeDialogHint, MSWindowsOwnDC = Qt::MSWindowsOwnDC, BypassWindowManagerHint = Qt::BypassWindowManagerHint, X11BypassWindowManagerHint = Qt::X11BypassWindowManagerHint, FramelessWindowHint = Qt::FramelessWindowHint, WindowTitleHint = Qt::WindowTitleHint, WindowSystemMenuHint = Qt::WindowSystemMenuHint, WindowMinimizeButtonHint = Qt::WindowMinimizeButtonHint, WindowMaximizeButtonHint = Qt::WindowMaximizeButtonHint, WindowMinMaxButtonsHint = Qt::WindowMinMaxButtonsHint, WindowContextHelpButtonHint = Qt::WindowContextHelpButtonHint, WindowShadeButtonHint = Qt::WindowShadeButtonHint, WindowStaysOnTopHint = Qt::WindowStaysOnTopHint, WindowTransparentForInput = Qt::WindowTransparentForInput, WindowOverridesSystemGestures = Qt::WindowOverridesSystemGestures, WindowDoesNotAcceptFocus = Qt::WindowDoesNotAcceptFocus, MaximizeUsingFullscreenGeometryHint = Qt::MaximizeUsingFullscreenGeometryHint, CustomizeWindowHint = Qt::CustomizeWindowHint, WindowStaysOnBottomHint = Qt::WindowStaysOnBottomHint, WindowCloseButtonHint = Qt::WindowCloseButtonHint, MacWindowToolBarButtonHint = Qt::MacWindowToolBarButtonHint, BypassGraphicsProxyWidget = Qt::BypassGraphicsProxyWidget, NoDropShadowWindowHint = Qt::NoDropShadowWindowHint, WindowFullscreenButtonHint = Qt::WindowFullscreenButtonHint}; + Widget = Qt::Widget, Window = Qt::Window, Dialog = Qt::Dialog, Sheet = Qt::Sheet, Drawer = Qt::Drawer, Popup = Qt::Popup, Tool = Qt::Tool, ToolTip = Qt::ToolTip, SplashScreen = Qt::SplashScreen, Desktop = Qt::Desktop, SubWindow = Qt::SubWindow, ForeignWindow = Qt::ForeignWindow, CoverWindow = Qt::CoverWindow, WindowType_Mask = Qt::WindowType_Mask, MSWindowsFixedSizeDialogHint = Qt::MSWindowsFixedSizeDialogHint, MSWindowsOwnDC = Qt::MSWindowsOwnDC, BypassWindowManagerHint = Qt::BypassWindowManagerHint, X11BypassWindowManagerHint = Qt::X11BypassWindowManagerHint, FramelessWindowHint = Qt::FramelessWindowHint, WindowTitleHint = Qt::WindowTitleHint, WindowSystemMenuHint = Qt::WindowSystemMenuHint, WindowMinimizeButtonHint = Qt::WindowMinimizeButtonHint, WindowMaximizeButtonHint = Qt::WindowMaximizeButtonHint, WindowMinMaxButtonsHint = Qt::WindowMinMaxButtonsHint, WindowContextHelpButtonHint = Qt::WindowContextHelpButtonHint, WindowShadeButtonHint = Qt::WindowShadeButtonHint, WindowStaysOnTopHint = Qt::WindowStaysOnTopHint, WindowTransparentForInput = Qt::WindowTransparentForInput, WindowOverridesSystemGestures = Qt::WindowOverridesSystemGestures, WindowDoesNotAcceptFocus = Qt::WindowDoesNotAcceptFocus, MaximizeUsingFullscreenGeometryHint = Qt::MaximizeUsingFullscreenGeometryHint, CustomizeWindowHint = Qt::CustomizeWindowHint, WindowStaysOnBottomHint = Qt::WindowStaysOnBottomHint, WindowCloseButtonHint = Qt::WindowCloseButtonHint, MacWindowToolBarButtonHint = Qt::MacWindowToolBarButtonHint, BypassGraphicsProxyWidget = Qt::BypassGraphicsProxyWidget, NoDropShadowWindowHint = Qt::NoDropShadowWindowHint, WindowFullscreenButtonHint = Qt::WindowFullscreenButtonHint, WindowOkButtonHint = Qt::WindowOkButtonHint, WindowCancelButtonHint = Qt::WindowCancelButtonHint}; Q_DECLARE_FLAGS(Alignment, AlignmentFlag) Q_DECLARE_FLAGS(DockWidgetAreas, DockWidgetArea) Q_DECLARE_FLAGS(DropActions, DropAction) From b534dad7afa5f5b10e0cee9c185121742d242157 Mon Sep 17 00:00:00 2001 From: Christoph Willing Date: Sun, 11 Jun 2017 12:03:08 -0400 Subject: [PATCH 36/37] Update README.md to describe the "patched-8" branch --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ad19c2da..b02fbd4c 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,12 @@ Additional configure options are: Available branches ------------------ -This repository contains 7 branches: +This repository contains 8 branches: + +### patched-8 +* Based on [r455](http://sourceforge.net/p/pythonqt/code/455/) with: + * revert of [r444](http://sourceforge.net/p/pythonqt/code/444/) + * all changes from ``patched-7`` cherry-picked. ### patched-7 * Based on [r443](http://sourceforge.net/p/pythonqt/code/443/) with: From c95ab554a4d74863d511837a1476a57bec1fb2be Mon Sep 17 00:00:00 2001 From: Christoph Willing Date: Mon, 12 Jun 2017 17:38:24 +1000 Subject: [PATCH 37/37] Restore inclusion of Qt5Core_PRIVATE_INCLUDE_DIRS Signed-off-by: Christoph Willing --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 57ab1fc0..03fdafc4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -150,6 +150,9 @@ if(PythonQt_QT_VERSION VERSION_GREATER "4") list(APPEND QT_LIBRARIES ${Qt5${qtlib}_LIBRARIES}) endforeach() + # Required for use of "QtCore/private/qmetaobjectbuilder_p.h" in "PythonQt.cpp" + include_directories(${Qt5Core_PRIVATE_INCLUDE_DIRS}) + set(QT_VERSION_MAJOR ${Qt5Core_VERSION_MAJOR}) set(QT_VERSION_MINOR ${Qt5Core_VERSION_MINOR})