Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. single function to accept different parameter types
Forum Updated to NodeBB v4.3 + New Features

single function to accept different parameter types

Scheduled Pinned Locked Moved Solved C++ Gurus
23 Posts 5 Posters 4.1k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M mzimmers
    28 Nov 2023, 15:12

    @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.

    J Offline
    J Offline
    J.Hilk
    Moderators
    wrote on 28 Nov 2023, 19:00 last edited by
    #21

    @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)
    

    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


    Q: What's that?
    A: It's blue light.
    Q: What does it do?
    A: It turns blue.

    M 1 Reply Last reply 28 Nov 2023, 20:24
    0
    • J J.Hilk
      28 Nov 2023, 19:00

      @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)
      
      M Offline
      M Offline
      mzimmers
      wrote on 28 Nov 2023, 20:24 last edited by
      #22

      @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.

      M 1 Reply Last reply 29 Nov 2023, 00:45
      0
      • M mzimmers
        28 Nov 2023, 20:24

        @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.

        M Offline
        M Offline
        mzimmers
        wrote on 29 Nov 2023, 00:45 last edited by mzimmers
        #23

        One 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...

        1 Reply Last reply
        0
        • M mzimmers has marked this topic as solved on 1 Dec 2023, 19:44

        21/23

        28 Nov 2023, 19:00

        • Login

        • Login or register to search.
        21 out of 23
        • First post
          21/23
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved