Solved Calling c++ method from QML.
-
Hi
I am trying to call a c++ method from a qml but I am not able to do so because of the error: undefined reference to 'vtable for Example'.My Code:
example.h
class Example: public QObject { Q_OBJECT public: explicit Example(QObject *parent = 0); Q_INVOKABLE bool example_method(int ); }
example.cpp
Example::Example(QObject *parent) : QObject(parent) {} bool Example::example_method() { ... }
main.cpp
int main() { ... Example adjust; engine.rootContext()->setContextProperty("example", &example); ... }
main.qml
Slider { ... onValueChanged: { example.example_method(value) } }
Please help how to fix this problem ?
-
class Example : public QObject { Q_OBJECT public: explicit Example(QObject *parent = 0); Q_INVOKABLE bool example_method(int ); virtual ~Example() override {} }
-
@Nifiro Still the same error.
-
@Ahti Do you have tried to call qmake and rebuild the project?
-
@KroMignon How to do it ? both ? I am a newbie to qt
-
or to really clean it,
and delete the build folder -
@mrjj Thanks I simple deleted the built and hit re-built and it worked thanks again :)