Skip to content

Python qt3 upgrade #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f2c1b29
Added CMake build system.
ericheim May 6, 2015
bd4e1e5
Added qt5 in testing and variable re-naming to match the previously u…
ericheim May 11, 2015
0fca79f
fixed rebase merge conflicts
ericheim May 11, 2015
1cb4c4f
fixed win32 linker issues and test build with qt5
ericheim May 12, 2015
36ab9c7
removed debug message
ericheim May 12, 2015
e31864b
Added Qt versions greater than 5.4 in cmake build. Use 5.4 wrappers a…
ericheim Feb 10, 2016
3388c4f
Update README.md to describe the "patched-5" branch
jcfr Aug 31, 2015
9ce3be3
Add missing refcount decrements when creating wrappers
msmolens Aug 28, 2015
a7e2b88
Fix refcount of PyInt_Type when creating enum wrapper
msmolens Aug 31, 2015
296b902
Prevent crash when an object is destroyed after calling PythonQt::cle…
msmolens Aug 28, 2015
f891954
fixed error handling for evalFile
May 29, 2015
aea3b94
fixed a missign QMetaObject::disconnect which leads to connection lea…
Jun 3, 2015
fd6082d
fixed test
Jun 4, 2015
857a7df
initial version that handles qualified virtual calls better
Jun 18, 2015
e40bdf9
improved handling of qualified virtual calls
Jun 18, 2015
0cb64a5
improved handling of qualified virtual calls
Jun 18, 2015
dbeb475
removed generating wrappers for virtual functions that are already de…
Jun 18, 2015
98d1c58
Enable "name" property support
msmolens Sep 1, 2015
e90a690
Update README.md to describe new commits
msmolens Sep 4, 2015
039d785
Prevent crashes during and after cleanup
msmolens Sep 11, 2015
a636d5a
Fix tests link error on Windows
msmolens Sep 11, 2015
9245264
Fix refcount problems seen when re-initializing Python after finalizing
msmolens Sep 11, 2015
e41b773
Explicitly initialize global storage containers
msmolens Sep 11, 2015
81e51e4
Add cleanup/finalization tests
msmolens Sep 11, 2015
af6cc54
Fix PythonQtSignalReceiver crash during cleanup
msmolens Sep 15, 2015
0171dce
Forked PythonQt 3.0 from Sourceforge and added CMake build system
ericheim Feb 17, 2016
72abf21
fixed rebase merge conflicts
ericheim May 11, 2015
7bbf27f
fixed win32 linker issues and test build with qt5
ericheim May 12, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 118 additions & 41 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ cmake_minimum_required(VERSION 2.8)
project(PythonQt)
#-----------------------------------------------------------------------------

include(CTestUseLaunchers OPTIONAL)

#----------------------------------------------------------------------------
# Qt version

set(PythonQt_QT_VERSION 5 CACHE STRING "Pick a version of Qt to use: 4 or 5")

set(minimum_required_qt5_version "5.3.0")
set(minimum_required_qt4_version "4.6.2")

#-----------------------------------------------------------------------------
# Python libraries

Expand All @@ -20,6 +30,13 @@ add_definitions(-DPYTHONQT_USE_RELEASE_PYTHON_FALLBACK)

#-----------------------------------------------------------------------------
# Build options
option(PythonQt_Wrap_QtAll "Make all Qt components available in python" OFF)

if(PythonQt_QT_VERSION MATCHES 4)
set(qtlibs core gui network opengl sql svg uitools webkit xml xmlpatterns locale)
else()
set(qtlibs Core Network OpenGL Sql Svg Widgets WebKitWidgets Xml XmlPatterns UiTools)
endif()

if(NOT DEFINED PythonQt_INSTALL_RUNTIME_DIR)
set(PythonQt_INSTALL_RUNTIME_DIR bin)
Expand All @@ -39,14 +56,13 @@ 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)
foreach(qtlib ${qtlibs})
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 :(
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)
Expand All @@ -65,42 +81,92 @@ endif()
#-----------------------------------------------------------------------------
# Setup Qt

set(minimum_required_qt_version "4.6.2")
if(PythonQt_QT_VERSION MATCHES 5)

find_package(Qt4)
if(BUILD_TESTING)
list(APPEND qtlibs Test)
endif()

if(QT4_FOUND)
find_package(Qt5 ${minimum_required_qt5_version} COMPONENTS ${qtlibs} REQUIRED)

set(found_qt_version ${QT_VERSION_MAJOR}.${QT_VERSION_MINOR}.${QT_VERSION_PATCH})
if(Qt5_DIR)
get_filename_component(_Qt5_DIR "${Qt5_DIR}/../../../" ABSOLUTE)
list(FIND CMAKE_PREFIX_PATH "${_Qt5_DIR}" _result)
if(_result LESS 0)
set(CMAKE_PREFIX_PATH "${_Qt5_DIR};${CMAKE_PREFIX_PATH}" CACHE PATH "" FORCE)
endif()
endif()

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}.")
get_target_property(_qmake_exec Qt5::qmake LOCATION)
execute_process(COMMAND ${_qmake_exec} -query QT_INSTALL_BINS
RESULT_VARIABLE _result
OUTPUT_VARIABLE QT_BINARY_DIR
ERROR_VARIABLE _error
)
string(STRIP "${QT_BINARY_DIR}" QT_BINARY_DIR)
if(_result OR NOT EXISTS "${QT_BINARY_DIR}")
message(FATAL_ERROR "Could not determine Qt binary directory: ${_result} ${QT_BINARY_DIR} ${_error}")
endif()

# Enable required qt module
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}")
endif()
set(QT_USE_QT${qtlib_uppercase} ${PythonQt_Wrap_Qt${qtlib}})
set(QT_LIBRARIES )
foreach(qtlib ${qtlibs})
include_directories(${Qt5${qtlib}_INCLUDE_DIRS})
list(APPEND QT_LIBRARIES ${Qt5${qtlib}_LIBRARIES})
add_definitions(${Qt5${qtlib}_DEFINITIONS})
endforeach()

set(QT_USE_QTTEST ${BUILD_TESTING})
#-----------------------------------------------------------------------------
# The variable "generated_cpp_suffix" allows to conditionnally compile the generated wrappers
# associated with the Qt version being used.
set(generated_cpp_suffix "_${Qt5Core_VERSION_MAJOR}${Qt5Core_VERSION_MINOR}")

# Use Qt5.4 as default for higher versions like it's done in build/common.prf
if(${Qt5Core_VERSION_MINOR} GREATER 4)
set(generated_cpp_suffix "_${Qt5Core_VERSION_MAJOR}4")
endif()


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()
#-----------------------------------------------------------------------------
# Setup Qt4

#-----------------------------------------------------------------------------
# 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")
set(generated_cpp_suffix "_47") # Also use 4.7 wrappers for 4.6.x version
endif()
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_qt4_version})
message(FATAL_ERROR "error: PythonQt requires Qt >= ${minimum_required_qt4_version} -- you cannot use Qt ${found_qt_version}.")
endif()

# Enable required qt module
foreach(qtlib ${qtlibs})
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()

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")
endif()

#-----------------------------------------------------------------------------
# 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}")

# TODO: generated headers for Qt4.8 contains several locales that are not available
# out of the box -> force 4.7
if("${generated_cpp_suffix}" STREQUAL "_46" OR "${generated_cpp_suffix}" STREQUAL "_48")
set(generated_cpp_suffix "_47") # Also use 4.7 wrappers for 4.6.x version
endif()
endif()
#-----------------------------------------------------------------------------
# Sources

Expand All @@ -124,8 +190,6 @@ set(sources
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
generated_cpp${generated_cpp_suffix}/com_trolltech_qt_core_builtin/com_trolltech_qt_core_builtin_init.cpp
generated_cpp${generated_cpp_suffix}/com_trolltech_qt_gui_builtin/com_trolltech_qt_gui_builtin0.cpp
Expand Down Expand Up @@ -157,12 +221,14 @@ 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
src/PythonQtUtils.h
)

if(PythonQt_QT_VERSION MATCHES 4)
set(sources ${sources} generated_cpp${generated_cpp_suffix}/PythonQt_QtBindings.cpp)
set(headers ${headers} generated_cpp${generated_cpp_suffix}/PythonQt_QtBindings.h)
endif()
#-----------------------------------------------------------------------------
# Headers that should run through moc

Expand All @@ -178,7 +244,7 @@ set(moc_sources

#-----------------------------------------------------------------------------
# Add extra sources
foreach(qtlib core gui network opengl sql svg uitools webkit xml xmlpatterns)
foreach(qtlib ${qtlibs})

if (${PythonQt_Wrap_Qt${qtlib}})

Expand Down Expand Up @@ -215,10 +281,15 @@ 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})

if(PythonQt_QT_VERSION MATCHES 4)
qt4_wrap_cpp(gen_moc_sources ${moc_sources})
qt4_wrap_ui(gen_ui_sources ${ui_sources})
qt4_add_resources(gen_qrc_sources ${qrc_sources})
else()
qt5_wrap_cpp(gen_moc_sources ${moc_sources})
qt5_wrap_ui(gen_ui_sources ${ui_sources})
qt5_add_resources(gen_qrc_sources ${qrc_sources})
endif()
#-----------------------------------------------------------------------------
# Build the library

Expand Down Expand Up @@ -271,19 +342,25 @@ if(BUILD_TESTING)
tests/PythonQtTests.cpp
tests/PythonQtTests.h
)

QT4_WRAP_CPP(test_sources
tests/PythonQtTests.h
)
if(PythonQt_QT_VERSION MATCHES 4)
QT4_WRAP_CPP(test_sources
tests/PythonQtTests.h
)
else()
QT5_WRAP_CPP(test_sources
tests/PythonQtTests.h
)
endif()

set_property(SOURCE tests/PythonQtTestMain.cpp PROPERTY COMPILE_DEFINITIONS "main=tests_PythonQtTestMain")

add_executable(PythonQtCppTests ${test_sources})
target_link_libraries(PythonQtCppTests PythonQt)
target_link_libraries(PythonQtCppTests PythonQt ${Qt5Test_LIBRARIES})

add_test(
NAME tests_PythonQtTestMain
COMMAND ${Slicer_LAUNCH_COMMAND} $<TARGET_FILE:PythonQtCppTests> tests/PythonQtTestMain
)
endif()


17 changes: 14 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -43,8 +43,19 @@ 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 + [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
* 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/)
Expand Down
12 changes: 0 additions & 12 deletions generator/abstractmetalang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,18 +696,6 @@ QString AbstractMetaFunction::targetLangSignature(bool minimal) const

// Attributes...
if (!minimal) {
#if 0 // jambi
if (isPublic()) s += "public ";
else if (isProtected()) s += "protected ";
else if (isPrivate()) s += "private ";

// if (isNative()) s += "native ";
// else
if (isFinalInTargetLang()) s += "final ";
else if (isAbstract()) s += "abstract ";

if (isStatic()) s += "static ";
#endif
// Return type
if (type())
s += type()->name() + " ";
Expand Down
12 changes: 12 additions & 0 deletions generator/shellgenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,18 @@ bool ShellGenerator::functionHasNonConstReferences(const AbstractMetaFunction* f
return false;
}

bool ShellGenerator::functionNeedsNormalWrapperSlot(const AbstractMetaFunction* func, const AbstractMetaClass* currentClass)
{
if (func->isSlot()) {
return false;
}
else if (func->isVirtual()) {
return func->declaringClass() == currentClass;
} else {
return true;
}
}

AbstractMetaFunctionList ShellGenerator::getFunctionsToWrap(const AbstractMetaClass* meta_class)
{
AbstractMetaFunctionList functions = meta_class->queryFunctions(
Expand Down
2 changes: 2 additions & 0 deletions generator/shellgenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class ShellGenerator : public Generator

bool functionHasNonConstReferences(const AbstractMetaFunction* func);

bool functionNeedsNormalWrapperSlot(const AbstractMetaFunction* func, const AbstractMetaClass* currentClass);

static QString shellClassName(const AbstractMetaClass *meta_class) {
return "PythonQtShell_" + meta_class->name();
}
Expand Down
Loading