diff --git a/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_sip.h b/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_sip.h index a2712ca..be2e882 100644 --- a/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_sip.h +++ b/src/pybind11-qt/include/pybind11_qt/details/pybind11_qt_sip.h @@ -52,16 +52,28 @@ namespace pybind11::detail::qt { } } - template && !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 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 , QClass> && + std::is_lvalue_reference_v && !is_pointer, + int> = 0> + operator U() { return value; } - template && !is_pointer, int> = 0> - operator T&&() && + template , QClass> && + std::is_rvalue_reference_v && !is_pointer, + int> = 0> + operator U() && { return std::move(value); } diff --git a/tests/python/CMakeLists.txt b/tests/python/CMakeLists.txt index 3c4e2dd..8cefd01 100644 --- a/tests/python/CMakeLists.txt +++ b/tests/python/CMakeLists.txt @@ -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) diff --git a/tests/runner/CMakeLists.txt b/tests/runner/CMakeLists.txt index 45b6305..71a6843 100644 --- a/tests/runner/CMakeLists.txt +++ b/tests/runner/CMakeLists.txt @@ -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)