-
Notifications
You must be signed in to change notification settings - Fork 92
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
Qt6 compatibility fixes for core PythonQt library #109
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1015,17 +1015,17 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) | |
if (wrap->classInfo()->isCPPWrapper()) { | ||
if (wrap->classInfo()->metaTypeId()>0) { | ||
// construct a new variant from the C++ object if it has a meta type (this will COPY the object!) | ||
v = QVariant(wrap->classInfo()->metaTypeId(), wrap->_wrappedPtr); | ||
v = QVariant(QMetaType(wrap->classInfo()->metaTypeId()), wrap->_wrappedPtr); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a note: It seems this constructor of QVariant only exists for Qt6, so we can't merge this as is into master, as this would break compatibility with Qt5. |
||
} else { | ||
// TODOXXX we could as well check if there is a registered meta type for "classname*", so that we may pass | ||
// the pointer here... | ||
// is this worth anything? we loose the knowledge of the cpp object type | ||
v = qVariantFromValue(wrap->_wrappedPtr); | ||
v = QVariant::fromValue(wrap->_wrappedPtr); | ||
} | ||
} else { | ||
// this gives us a QObject pointer | ||
QObject* myObject = wrap->_obj; | ||
v = qVariantFromValue(myObject); | ||
v = QVariant::fromValue(myObject); | ||
} | ||
return v; | ||
} else if (val == Py_None) { | ||
|
@@ -1073,55 +1073,55 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) | |
case QMetaType::Float: | ||
{ | ||
float d = (float) PyObjGetDouble(val,false,ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
case QMetaType::Long: | ||
{ | ||
long d = (long) PyObjGetLongLong(val,false,ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
case QMetaType::ULong: | ||
{ | ||
unsigned long d = (unsigned long) PyObjGetLongLong(val,false,ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
case QMetaType::LongLong: | ||
{ | ||
qint64 d = PyObjGetLongLong(val, false, ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
case QMetaType::ULongLong: | ||
{ | ||
quint64 d = PyObjGetULongLong(val, false, ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
case QMetaType::Short: | ||
{ | ||
short d = (short) PyObjGetInt(val,false,ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
case QMetaType::UShort: | ||
{ | ||
unsigned short d = (unsigned short) PyObjGetInt(val,false,ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
case QMetaType::Char: | ||
{ | ||
char d = (char) PyObjGetInt(val,false,ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
case QMetaType::UChar: | ||
{ | ||
unsigned char d = (unsigned char) PyObjGetInt(val,false,ok); | ||
if (ok) v = qVariantFromValue(d); | ||
if (ok) v = QVariant::fromValue(d); | ||
} | ||
break; | ||
|
||
|
@@ -1189,7 +1189,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) | |
PythonQtInstanceWrapper* wrap = (PythonQtInstanceWrapper*)val; | ||
if (wrap->classInfo()->isCPPWrapper() && wrap->classInfo()->metaTypeId() == type) { | ||
// construct a new variant from the C++ object if it has the same meta type | ||
v = QVariant(type, wrap->_wrappedPtr); | ||
v = QVariant(QMetaType(type), wrap->_wrappedPtr); | ||
} else { | ||
// Try to convert the object to a QVariant based on the typeName | ||
bool ok; | ||
|
@@ -1202,10 +1202,10 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) | |
void* object = castWrapperTo(wrap, typeName, ok); | ||
if (ok) { | ||
if (isPtr) { | ||
v = QVariant(type, &object); | ||
v = QVariant(QMetaType(type), &object); | ||
} | ||
else { | ||
v = QVariant(type, object); | ||
v = QVariant(QMetaType(type), object); | ||
} | ||
} | ||
} | ||
|
@@ -1215,7 +1215,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) | |
PythonQtConvertPythonToMetaTypeCB* converter = _pythonToMetaTypeConverters.value(type); | ||
if (converter) { | ||
// allocate a default object of the needed type: | ||
v = QVariant(type, (const void*)nullptr); | ||
v = QVariant(QMetaType(type), (const void*)nullptr); | ||
// now call the converter, passing the internal object of the variant | ||
ok = (*converter)(val, (void*)v.constData(), type, true); | ||
if (!ok) { | ||
|
@@ -1226,7 +1226,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type) | |
const PythonQtMethodInfo::ParameterInfo& info = PythonQtMethodInfo::getParameterInfoForMetaType(type); | ||
if (info.isQList && (info.innerNamePointerCount == 1)) { | ||
// allocate a default object of the needed type: | ||
v = QVariant(type, (const void*)nullptr); | ||
v = QVariant(QMetaType(type), (const void*)nullptr); | ||
ok = ConvertPythonListToQListOfPointerType(val, (QList<void*>*)v.constData(), info, true); | ||
if (!ok) { | ||
v = QVariant(); | ||
|
@@ -1461,7 +1461,7 @@ QString PythonQtConv::CPPObjectToString(int type, const void* data) { | |
// this creates a copy, but that should not be expensive for typical simple variants | ||
// (but we do not want to do this for our won user types! | ||
if (type>0 && type < (int)QVariant::UserType) { | ||
QVariant v(type, data); | ||
QVariant v(QMetaType(type), data); | ||
r = v.toString(); | ||
} | ||
} | ||
|
@@ -1483,11 +1483,6 @@ PyObject* PythonQtConv::createCopyFromMetaType( int type, const void* data ) | |
return (PyObject*)wrap; | ||
} | ||
|
||
PyObject* PythonQtConv::convertFromStringRef(const void* inObject, int /*metaTypeId*/) | ||
{ | ||
return PythonQtConv::QStringToPyObject(((QStringRef*)inObject)->toString()); | ||
} | ||
|
||
QByteArray PythonQtConv::getCPPTypeName(PyObject* type) | ||
{ | ||
QByteArray result; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# $Source$ | ||
# -------------------------------------------------- | ||
|
||
TARGET = PythonQt-Qt5-PythonXY | ||
TARGET = PythonQt-Qt6-PythonXY | ||
TEMPLATE = lib | ||
|
||
DESTDIR = ../lib | ||
|
@@ -25,12 +25,16 @@ isEmpty(PYTHONQT_STATIC) { | |
|
||
DEFINES += PYTHONQT_CATCH_ALL_EXCEPTIONS | ||
|
||
contains(QT_MAJOR_VERSION, 5) { | ||
contains(QT_MAJOR_VERSION, 6) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: Perhaps use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As this is for Qt5 and 6 only, there is no need for the check at all. |
||
QT += widgets core-private | ||
} | ||
|
||
INCLUDEPATH += $$PWD | ||
|
||
macx { | ||
QMAKE_APPLE_DEVICE_ARCHS = x86_64 arm64 | ||
} | ||
|
||
include ( ../build/common.prf ) | ||
include ( ../build/python.prf ) | ||
TARGET = $$replace(TARGET, PythonXY, Python$${PYTHON_VERSION}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both memberList() and propertyList() return a new QStringList object; it isn't a valid use to use begin() and end() from different list instances, even if it seems to work for you.
Assign the result of memberList() and propertyList() to a local variable and use begin() and end() on that.