Merge pull request #108 from Holt59/fix/qt-type-caster

Fix Qt type caster for latest pybind11
This commit is contained in:
Mikaël Capelle
2023-07-02 13:55:47 +02:00
committed by GitHub
3 changed files with 25 additions and 8 deletions
@@ -52,16 +52,28 @@ namespace pybind11::detail::qt {
}
}
template <class T,
std::enable_if_t<std::is_same_v<T, QClass> && !is_pointer, int> = 0>
operator T&()
// pybind11 requires operator T&() & and operator T&&() && but here we want to
// use SFINAE with is_pointer so we need to template the operator
//
// having a template <class U> operator U&&() does not work since it will not
// deduce the proper return type for QClass&& or QClass& so we have two separate
// overloads, and in each one, U is actually a reference type (lvalue or rvalue)
//
template <class U,
std::enable_if_t<std::is_same_v<std::remove_reference_t<U>, QClass> &&
std::is_lvalue_reference_v<U> && !is_pointer,
int> = 0>
operator U()
{
return value;
}
template <class T,
std::enable_if_t<std::is_same_v<T, QClass> && !is_pointer, int> = 0>
operator T&&() &&
template <class U,
std::enable_if_t<std::is_same_v<std::remove_reference_t<U>, QClass> &&
std::is_rvalue_reference_v<U> && !is_pointer,
int> = 0>
operator U() &&
{
return std::move(value);
}
+3 -1
View File
@@ -30,7 +30,9 @@ QT_ROOT=set:${QT_ROOT}"
mo2_python_pip_install(python-tests
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pylibs
PACKAGES pytest PyQt6==6.3.0)
PACKAGES pytest
PyQt${QT_MAJOR_VERSION}==${QT_VERSION}
PyQt${QT_MAJOR_VERSION}-Qt${QT_MAJOR_VERSION}==${QT_VERSION})
add_dependencies(python-tests mobase)
set_target_properties(python-tests PROPERTIES FOLDER tests/python)
+4 -1
View File
@@ -19,7 +19,10 @@ target_link_libraries(runner-tests PUBLIC runner)
set(PYLIB_DIR ${CMAKE_CURRENT_BINARY_DIR}/pylibs)
mo2_python_pip_install(runner-tests
DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/pylibs
PACKAGES pytest PyQt6==6.4.0)
PACKAGES
pytest
PyQt${QT_MAJOR_VERSION}==${QT_VERSION}
PyQt${QT_MAJOR_VERSION}-Qt${QT_MAJOR_VERSION}==${QT_VERSION})
add_dependencies(runner-tests mobase)