Skip to content

Commit 6b1064e

Browse files
mrbean-bremenjcfr
authored andcommitted
[Backport] Fix type conversion warnings, use const
- remove unused variable (cherry picked from commit MeVisLab/pythonqt@17cf766)
1 parent a646ede commit 6b1064e

9 files changed

+40
-40
lines changed

src/PythonQt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ void PythonQt::init(int flags, const QByteArray& pythonQtModuleName)
266266
"QtSystemMsg"
267267
};
268268

269-
for (int i = 0; i<sizeof(enumValues)/sizeof(int); i++) {
269+
for (auto i = 0u; i<sizeof(enumValues)/sizeof(int); i++) {
270270
PyObject* obj = PyInt_FromLong(enumValues[i]);
271271
PyModule_AddObject(pack, enumNames[i], obj);
272272
Py_INCREF(obj);
@@ -2184,7 +2184,7 @@ const QMetaObject* PythonQtPrivate::buildDynamicMetaObject(PythonQtClassWrapper*
21842184
if (signal->_dynamicInfo) {
21852185
signal->_dynamicInfo->name = PyString_AsString(key);
21862186
foreach(QByteArray sig, signal->_dynamicInfo->signatures) {
2187-
QMetaMethodBuilder method = builder.addSignal(signal->_dynamicInfo->name + "(" + sig + ")");
2187+
builder.addSignal(signal->_dynamicInfo->name + "(" + sig + ")");
21882188
needsMetaObject = true;
21892189
}
21902190
}

src/PythonQtClassWrapper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,16 @@ PyObject *PythonQtClassWrapper_inherits(PythonQtClassWrapper *type, PyObject *ar
419419

420420

421421
static PyMethodDef PythonQtClassWrapper_methods[] = {
422-
{"className", (PyCFunction)PythonQtClassWrapper_classname, METH_NOARGS,
422+
{"className", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtClassWrapper_classname)), METH_NOARGS,
423423
"Return the classname of the object"
424424
},
425-
{"inherits", (PyCFunction)PythonQtClassWrapper_inherits, METH_VARARGS,
425+
{"inherits", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtClassWrapper_inherits)), METH_VARARGS,
426426
"Returns if the class inherits or is of given type name"
427427
},
428-
{"help", (PyCFunction)PythonQtClassWrapper_help, METH_NOARGS,
428+
{"help", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtClassWrapper_help)), METH_NOARGS,
429429
"Shows the help of available methods for this class"
430430
},
431-
{"delete", (PyCFunction)PythonQtClassWrapper_delete, METH_VARARGS,
431+
{"delete", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtClassWrapper_delete)), METH_VARARGS,
432432
"Deletes the given C++ object"
433433
},
434434
{nullptr, nullptr, 0 , nullptr} /* Sentinel */

src/PythonQtConversion.cpp

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -503,16 +503,16 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
503503
break;
504504
case QMetaType::Long:
505505
{
506-
qint64 val = PyObjGetLongLong(obj, strict, ok);
506+
auto val = PyObjGetLongLong(obj, strict, ok);
507507
if (ok && (val >= LONG_MIN && val <= LONG_MAX)) {
508508
PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, long, val, ptr);
509509
}
510510
}
511511
break;
512512
case QMetaType::ULong:
513513
{
514-
qint64 val = (unsigned long)PyObjGetLongLong(obj, strict, ok);
515-
if (ok && (val >= 0 && val <= ULONG_MAX)) {
514+
auto val = PyObjGetULongLong(obj, strict, ok);
515+
if (ok && val <= ULONG_MAX) {
516516
PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, unsigned long, val, ptr);
517517
}
518518
}
@@ -535,7 +535,7 @@ void* PythonQtConv::ConvertPythonToQt(const PythonQtMethodInfo::ParameterInfo& i
535535
break;
536536
case QMetaType::UInt:
537537
{
538-
quint64 val = PyObjGetLongLong(obj, strict, ok);
538+
auto val = PyObjGetLongLong(obj, strict, ok);
539539
if (ok && (val >= 0 && val <= UINT_MAX)) {
540540
PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedCPPObject, frame, unsigned int, val, ptr);
541541
}
@@ -1066,26 +1066,26 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
10661066
{
10671067
double d = PyObjGetDouble(val,false,ok);
10681068
if (ok) v = QVariant(d);
1069-
break;
10701069
}
1070+
break;
10711071
case QMetaType::Float:
10721072
{
10731073
float d = (float) PyObjGetDouble(val,false,ok);
10741074
if (ok) v = qVariantFromValue(d);
1075-
break;
10761075
}
1076+
break;
10771077
case QMetaType::Long:
10781078
{
10791079
long d = (long) PyObjGetLongLong(val,false,ok);
10801080
if (ok) v = qVariantFromValue(d);
1081-
break;
10821081
}
1082+
break;
10831083
case QMetaType::ULong:
10841084
{
10851085
unsigned long d = (unsigned long) PyObjGetLongLong(val,false,ok);
10861086
if (ok) v = qVariantFromValue(d);
1087-
break;
10881087
}
1088+
break;
10891089
case QMetaType::LongLong:
10901090
{
10911091
qint64 d = PyObjGetLongLong(val, false, ok);
@@ -1102,26 +1102,26 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
11021102
{
11031103
short d = (short) PyObjGetInt(val,false,ok);
11041104
if (ok) v = qVariantFromValue(d);
1105-
break;
11061105
}
1106+
break;
11071107
case QMetaType::UShort:
11081108
{
11091109
unsigned short d = (unsigned short) PyObjGetInt(val,false,ok);
11101110
if (ok) v = qVariantFromValue(d);
1111-
break;
11121111
}
1112+
break;
11131113
case QMetaType::Char:
11141114
{
11151115
char d = (char) PyObjGetInt(val,false,ok);
11161116
if (ok) v = qVariantFromValue(d);
1117-
break;
11181117
}
1118+
break;
11191119
case QMetaType::UChar:
11201120
{
11211121
unsigned char d = (unsigned char) PyObjGetInt(val,false,ok);
11221122
if (ok) v = qVariantFromValue(d);
1123-
break;
11241123
}
1124+
break;
11251125

11261126
case QVariant::ByteArray:
11271127
{
@@ -1133,6 +1133,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
11331133
#endif
11341134
break;
11351135
}
1136+
break;
11361137
case QVariant::String:
11371138
{
11381139
bool ok;
@@ -1207,7 +1208,7 @@ QVariant PythonQtConv::PyObjToQVariant(PyObject* val, int type)
12071208
}
12081209
}
12091210
}
1210-
} else if (type >= QVariant::UserType) {
1211+
} else if (static_cast<std::uint32_t>(type) >= QVariant::UserType) {
12111212
// not an instance wrapper, but there might be other converters
12121213
// Maybe we have a special converter that is registered for that type:
12131214
PythonQtConvertPythonToMetaTypeCB* converter = _pythonToMetaTypeConverters.value(type);

src/PythonQtInstanceWrapper.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,16 @@ PyObject *PythonQtInstanceWrapper_delete(PythonQtInstanceWrapper * self)
359359

360360

361361
static PyMethodDef PythonQtInstanceWrapper_methods[] = {
362-
{"className", (PyCFunction)PythonQtInstanceWrapper_classname, METH_NOARGS,
362+
{"className", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtInstanceWrapper_classname)), METH_NOARGS,
363363
"Return the classname of the object"
364364
},
365-
{"inherits", (PyCFunction)PythonQtInstanceWrapper_inherits, METH_VARARGS,
365+
{"inherits", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtInstanceWrapper_inherits)), METH_VARARGS,
366366
"Returns if the class inherits or is of given type name"
367367
},
368-
{"help", (PyCFunction)PythonQtInstanceWrapper_help, METH_NOARGS,
368+
{"help", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtInstanceWrapper_help)), METH_NOARGS,
369369
"Shows the help of available methods for this class"
370370
},
371-
{"delete", (PyCFunction)PythonQtInstanceWrapper_delete, METH_NOARGS,
371+
{"delete", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtInstanceWrapper_delete)), METH_NOARGS,
372372
"Deletes the C++ object (at your own risk, my friend!)"
373373
},
374374
{nullptr, nullptr, 0, nullptr} /* Sentinel */

src/PythonQtMethodInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ PythonQtMethodInfo::PythonQtMethodInfo(const QByteArray& typeName, const QList<Q
8585
void PythonQtMethodInfo::setupAllowThreads()
8686
{
8787
bool allowThreads = true;
88-
for (const ParameterInfo& info : _parameters) {
88+
for (const ParameterInfo& info : qAsConst(_parameters)) {
8989
if (info.name == "PyObject" || info.name == "PythonQtObjectPtr" ||
9090
info.innerName == "PyObject" || info.innerName == "PythonQtObjectPtr") {
9191
allowThreads = false;

src/PythonQtSignal.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,22 +295,22 @@ static PyObject *PythonQtSignalFunction_emit(PythonQtSignalFunctionObject* func,
295295
}
296296

297297
static PyMethodDef meth_methods[] = {
298-
{"parameterTypes", (PyCFunction)PythonQtSignalFunction_parameterTypes, METH_NOARGS,
298+
{"parameterTypes", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSignalFunction_parameterTypes)), METH_NOARGS,
299299
"Returns a tuple of tuples of the C++ parameter types for all overloads of the signal"
300300
},
301-
{"parameterNames", (PyCFunction)PythonQtSignalFunction_parameterNames, METH_NOARGS,
301+
{"parameterNames", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSignalFunction_parameterNames)), METH_NOARGS,
302302
"Returns a tuple of tuples of the C++ parameter type names (if available), for all overloads of the signal"
303303
},
304-
{"typeName", (PyCFunction)PythonQtSignalFunction_typeName, METH_NOARGS,
304+
{"typeName", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSignalFunction_typeName)), METH_NOARGS,
305305
"Returns a tuple of the C++ return value types of each signal overload"
306306
},
307-
{"connect", (PyCFunction)PythonQtSignalFunction_connect, METH_VARARGS,
307+
{"connect", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSignalFunction_connect)), METH_VARARGS,
308308
"Connects the signal to the Python callable"
309309
},
310-
{"disconnect", (PyCFunction)PythonQtSignalFunction_disconnect, METH_VARARGS,
310+
{"disconnect", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSignalFunction_disconnect)), METH_VARARGS,
311311
"Disconnects the signal from the given Python callable or disconnects all if no argument is passed."
312312
},
313-
{"emit", (PyCFunction)PythonQtSignalFunction_emit, METH_VARARGS,
313+
{"emit", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSignalFunction_emit)), METH_VARARGS,
314314
"Emits the signal with given arguments"
315315
},
316316
{nullptr, nullptr, 0 , nullptr} /* Sentinel */
@@ -326,11 +326,11 @@ meth_repr(PythonQtSignalFunctionObject *f)
326326
if (f->m_self->ob_type == &PythonQtClassWrapper_Type) {
327327
PythonQtClassWrapper* self = (PythonQtClassWrapper*) f->m_self;
328328
return PyString_FromFormat("<unbound qt signal %s of %s type>",
329-
f->m_ml->slotName().data(),
329+
f->m_ml->slotName().constData(),
330330
self->classInfo()->className().constData());
331331
} else {
332332
return PyString_FromFormat("<qt signal %s of %s instance at %p>",
333-
f->m_ml->slotName().data(),
333+
f->m_ml->slotName().constData(),
334334
f->m_self->ob_type->tp_name,
335335
f->m_self);
336336
}
@@ -374,7 +374,7 @@ static PyObject*
374374
meth_richcompare(PythonQtSignalFunctionObject *a, PythonQtSignalFunctionObject *b, int op)
375375
{
376376
int x = meth_compare(a, b);
377-
bool r;
377+
bool r = false;
378378
if (op == Py_LT)
379379
r = x < 0;
380380
else if (op == Py_LE)

src/PythonQtSignalReceiver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ int PythonQtSignalReceiver::qt_metacall(QMetaObject::Call c, int id, void **argu
268268
}
269269

270270
bool shouldDelete = false;
271-
for(const PythonQtSignalTarget& t : _targets) {
271+
for(const PythonQtSignalTarget& t : qAsConst(_targets)) {
272272
if (t.slotId() == id) {
273273
const int sigId = t.signalId();
274274
t.call(arguments);

src/PythonQtSlot.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -704,13 +704,13 @@ PyObject *PythonQtMemberFunction_typeName(PythonQtSlotInfo* theInfo)
704704
}
705705

706706
static PyMethodDef meth_methods[] = {
707-
{"parameterTypes", (PyCFunction)PythonQtSlotFunction_parameterTypes, METH_NOARGS,
707+
{"parameterTypes", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSlotFunction_parameterTypes)), METH_NOARGS,
708708
"Returns a tuple of tuples of the C++ parameter types for all overloads of the slot"
709709
},
710-
{"parameterNames", (PyCFunction)PythonQtSlotFunction_parameterNames, METH_NOARGS,
710+
{"parameterNames", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSlotFunction_parameterNames)), METH_NOARGS,
711711
"Returns a tuple of tuples of the C++ parameter type names (if available), for all overloads of the slot"
712712
},
713-
{"typeName", (PyCFunction)PythonQtSlotFunction_typeName, METH_NOARGS,
713+
{"typeName", reinterpret_cast<PyCFunction>(reinterpret_cast<void*>(PythonQtSlotFunction_typeName)), METH_NOARGS,
714714
"Returns a tuple of the C++ return value types of each slot overload"
715715
},
716716
{nullptr, nullptr, 0 , nullptr} /* Sentinel */
@@ -722,11 +722,11 @@ meth_repr(PythonQtSlotFunctionObject *f)
722722
if (f->m_self->ob_type == &PythonQtClassWrapper_Type) {
723723
PythonQtClassWrapper* self = (PythonQtClassWrapper*) f->m_self;
724724
return PyString_FromFormat("<unbound qt slot %s of %s type>",
725-
f->m_ml->slotName().data(),
725+
f->m_ml->slotName().constData(),
726726
self->classInfo()->className().constData());
727727
} else {
728728
return PyString_FromFormat("<qt slot %s of %s instance at %p>",
729-
f->m_ml->slotName().data(),
729+
f->m_ml->slotName().constData(),
730730
f->m_self->ob_type->tp_name,
731731
f->m_self);
732732
}

src/gui/PythonQtScriptingConsole.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ void PythonQtScriptingConsole::keyPressEvent(QKeyEvent* event) {
464464
} else {
465465
_completer->popup()->hide();
466466
}
467-
eventHandled = true;
468467
}
469468
}
470469

0 commit comments

Comments
 (0)