register Quantity type for shiboken2, handle exception to fix abort when setting quantity property of InputField via Python

This commit is contained in:
wmayer
2016-12-30 22:51:17 +01:00
parent 39ddebc337
commit 4db41b0b4b
2 changed files with 8 additions and 7 deletions

View File

@@ -492,8 +492,13 @@ void InputField::setMinimum(double m)
void InputField::setUnitText(const QString& str)
{
Base::Quantity quant = Base::Quantity::parse(str);
setUnit(quant.getUnit());
try {
Base::Quantity quant = Base::Quantity::parse(str);
setUnit(quant.getUnit());
}
catch (...) {
// ignore exceptions
}
}
QString InputField::getUnitText(void)

View File

@@ -108,7 +108,7 @@ PyTypeObject** SbkPySide2_QtWidgetsTypes=NULL;
using namespace Gui;
#if defined (HAVE_SHIBOKEN) && defined(HAVE_PYSIDE)
#if defined (HAVE_SHIBOKEN)
namespace Shiboken {
template<> struct Converter<Base::Quantity>
{
@@ -150,13 +150,9 @@ PythonToCppFunc toCppPointerCheckFuncQuantity(PyObject* obj)
void registerTypes()
{
#if defined (HAVE_SHIBOKEN2)
//FIXME: This crashes with Shiboken2
#else
SbkConverter* convert = Shiboken::Conversions::createConverter(&Base::QuantityPy::Type, toPythonFuncQuantity);
Shiboken::Conversions::setPythonToCppPointerFunctions(convert, toCppPointerConvFuncQuantity, toCppPointerCheckFuncQuantity);
Shiboken::Conversions::registerConverterName(convert, "Base::Quantity");
#endif
}
#endif