So, I guess I figured out how to expose some C++ methods to QML.
The problem is that everytime I try to run my code I got the following error message: "undefined reference to `vtable for MyClass".
Any help on this?
The code:
Code:
class MyClass : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE void cppMethod(const QString &msg) {
qDebug() << "Called the C++ method with" << msg;
}
public slots:
void cppSlot(int number) {
qDebug() << "Called the C++ slot with" << number;
}
};
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QDeclarativeView view;
MyClass myClass;
view.rootContext()->setContextProperty("myObject", &myClass);
view.setSource(QUrl::fromLocalFile("qml/expose/main.qml"));
view.show();
return app.exec();
}