single function to accept different parameter types
-
@J-Hilk yes, that works when the caller of func() is a C++ function. When it's coming from QML, I get the bad_cast error.
So, I guess this isn't a C++ problem after all; it does have something to do with the interaction between C++ and QML. I can post something to the QML forum about it.
@mzimmers said in single function to accept different parameter types:
@J-Hilk yes, that works when the caller of func() is a C++ function. When it's coming from QML, I get the bad_cast error.
if its coming from qml, and you're passing the object into the call, than you're essentially already passing a pointer, I think.
Try
void EquipmentModel::sendPatchRequest(Equipment *equipment)
-
@mzimmers said in single function to accept different parameter types:
@J-Hilk yes, that works when the caller of func() is a C++ function. When it's coming from QML, I get the bad_cast error.
if its coming from qml, and you're passing the object into the call, than you're essentially already passing a pointer, I think.
Try
void EquipmentModel::sendPatchRequest(Equipment *equipment)
wrote on 28 Nov 2023, 20:24 last edited by@J-Hilk said in single function to accept different parameter types:
Try
void EquipmentModel::sendPatchRequest(Equipment *equipment)I did try that - I get a runtime error about passing incompatible arguments. And, I'm hardly a JS expert, but I don't think there's anything I can do on the QML side to make that signature work.
-
@J-Hilk said in single function to accept different parameter types:
Try
void EquipmentModel::sendPatchRequest(Equipment *equipment)I did try that - I get a runtime error about passing incompatible arguments. And, I'm hardly a JS expert, but I don't think there's anything I can do on the QML side to make that signature work.
wrote on 29 Nov 2023, 00:45 last edited by mzimmersOne of my co-workers came up with this workaround:
// would entail one of these routines for each subclass, // but they would all do the exact same thing. void EquipmentModel::sendPatchRequest(const Vsp &equipment) { sendBaseRequest(equipment); } void EquipmentModel::sendBaseRequest(const Equipment &equipment) { if (m_qnrPatch == nullptr) { int i = getIndex(equipment.m_uuid); if (i == NOT_IN_LIST) { continue; } Equipment &listEntry = *(*m_list)[i]; equipment.addPatchFields(listEntry, qjo, rolesToKeys); // goes to subclass function. ...
It works. Unless someone comes up with a better idea, I'll close out this topic. Thanks for all the suggestions...
-
21/23