diff --git a/src/runner/pythonRunner.pro b/src/runner/pythonRunner.pro index 55c509b..fee3b5e 100644 --- a/src/runner/pythonRunner.pro +++ b/src/runner/pythonRunner.pro @@ -42,7 +42,7 @@ CONFIG(debug, debug|release) { msvc:QMAKE_LFLAGS += /DEBUG } -INCLUDEPATH += "$${BOOSTPATH}" "$${PYTHONPATH}/include" "$${PYTHONPATH}/Lib/site-packages/PyQt5/include" ../uibase +INCLUDEPATH += "$${BOOSTPATH}" "$${PYTHONPATH}/include" "$${PYTHONPATH}/Lib/site-packages/PyQt6/include" ../uibase LIBS += -L"$${PYTHONPATH}/libs" -L"$${BOOSTPATH}/stage/lib" LIBS += -lpython27 LIBS += -luibase diff --git a/src/runner/pythonrunner.cpp b/src/runner/pythonrunner.cpp index 4c6dc01..8963b4d 100644 --- a/src/runner/pythonrunner.cpp +++ b/src/runner/pythonrunner.cpp @@ -67,8 +67,8 @@ BOOST_PYTHON_MODULE(mobase) { PyEval_InitThreads(); - bpy::import("PyQt5.QtCore"); - bpy::import("PyQt5.QtWidgets"); + bpy::import("PyQt6.QtCore"); + bpy::import("PyQt6.QtWidgets"); utils::register_qstring_converter(); utils::register_qvariant_converter(); @@ -112,7 +112,7 @@ BOOST_PYTHON_MODULE(mobase) utils::register_sequence_container>(); utils::register_sequence_container>(); utils::register_sequence_container>(); - //utils::register_sequence_container>(); + utils::register_sequence_container>(); utils::register_sequence_container(); utils::register_sequence_container>(); utils::register_sequence_container>(); diff --git a/src/runner/sipapiaccess.cpp b/src/runner/sipapiaccess.cpp index b2bceee..6d374c3 100644 --- a/src/runner/sipapiaccess.cpp +++ b/src/runner/sipapiaccess.cpp @@ -5,5 +5,54 @@ const sipAPIDef* sipAPIAccess::sipAPI() { - return (const sipAPIDef*)PyCapsule_Import("sip._C_API", 0); + QString exception; + static const sipAPIDef* sipApi = nullptr; + if (sipApi == nullptr) { + PyImport_ImportModule("PyQt6.sip"); + + auto errorObj = PyErr_Occurred(); + if (errorObj != NULL) { + PyObject* type, * value, * traceback; + PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); + if (traceback != NULL) { + boost::python::handle<> h_type(type); + boost::python::handle<> h_val(value); + boost::python::handle<> h_tb(traceback); + boost::python::object tb(boost::python::import("traceback")); + boost::python::object fmt_exp(tb.attr("format_exception")); + boost::python::object exp_list(fmt_exp(h_type, h_val, h_tb)); + boost::python::object exp_str(boost::python::str("\n").join(exp_list)); + boost::python::extract returned(exp_str); + exception = QString::fromStdString(returned()); + } + PyErr_Restore(type, value, traceback); + throw MOBase::Exception(QString("Failed to load PyQt6: %1").arg(exception)); + } + + sipApi = (const sipAPIDef*)PyCapsule_Import("PyQt6.sip._C_API", 0); + if (sipApi == NULL) { + auto errorObj = PyErr_Occurred(); + if (errorObj != NULL) { + PyObject* type, * value, * traceback; + PyErr_Fetch(&type, &value, &traceback); + PyErr_NormalizeException(&type, &value, &traceback); + if (traceback != NULL) { + boost::python::handle<> h_type(type); + boost::python::handle<> h_val(value); + boost::python::handle<> h_tb(traceback); + boost::python::object tb(boost::python::import("traceback")); + boost::python::object fmt_exp(tb.attr("format_exception")); + boost::python::object exp_list(fmt_exp(h_type, h_val, h_tb)); + boost::python::object exp_str(boost::python::str("\n").join(exp_list)); + boost::python::extract returned(exp_str); + exception = QString::fromStdString(returned()); + } + PyErr_Restore(type, value, traceback); + } + throw MOBase::Exception(QString("Failed to load SIP API: %1").arg(exception)); + } + } + + return sipApi; } \ No newline at end of file