TypeError: Property '...' of object ...(0x55fcc300c0d0) is not a function
-
Re: TypeError: Property '' of object QObject(0x6cfdf0) is not a function
Ok, I'm getting rather mad on this.
I just want to get a value of a bool im my C++ class:#ifndef HPC_MANAGER_H #define HPC_MANAGER_H #include <QObject> #include <QDebug> class hpc_manager : public QObject { Q_OBJECT private: bool occupiedOne = false; bool occupiedTwo = false; bool occupiedThree = false; int occupiedSlots = 0; public: explicit hpc_manager(QObject *parent = nullptr); bool chargerIsOccupied(); int getOccupiedSlots(); signals: public slots: void set_current_charger(int cs); }; #endif // HPC_MANAGER_H
I think I've set it up all right here...
#include "hpc_manager.h" hpc_manager::hpc_manager(QObject *parent) : QObject(parent) { } bool hpc_manager::chargerIsOccupied() { if(occupiedOne && occupiedTwo) return true; else if(occupiedOne && occupiedThree) return true; else if(occupiedTwo && occupiedThree) return true; else return false; } int hpc_manager::getOccupiedSlots() { return occupiedSlots; }
The int was just my last hope for this...
But everytime I try to get the infos within my Qml:
function slotSelected(id) { //console.log(hpcManager.getOccupiedSlots()) if(hpcManager.getOccupiedSlots === 2) { hpcManager.set_current_charger(id) t.running = false } else console.log("All Chargers are occupied!"); }
I get this "qrc:/WelcomeScreen.qml:73: TypeError: Property 'getOccupiedSlots' of object hpc_manager(0x55fcc300c0d0) is not a function"
Error. I tried different stuff like !== or so... but it's either unknown or simply just says "All chargers are occupied", but this can't be, because the value is set to "0" at the beginning.What am I missing here?
-
@Meistermosher To expose a function to C++ use Q_INVOKABLE or use a slot, for this change to:
Q_INVOKABLE int getOccupiedSlots();
and
if(hpcManager.getOccupiedSlots() == 2)
Please read the docs: https://doc.qt.io/qt-5/qtqml-cppintegration-exposecppattributes.html#exposing-methods-including-qt-slots
-
You, sir, are my rescue! :)
Thanks a lot! This saved me a lot of headache.