Undefined reference to `vtable for MyClass'
-
wrote on 2 Jun 2014, 10:17 last edited by
Hello, I'm newbie, practicing qt code. I'm trying to call c++ function from qml. But I have a problem, maybe there are few mistakes from code.
with QT 5.2.0 on UbuntuLet's check;
I got these issues(3)
@
In function 'MyClass::MyClass()':
undefined reference to `vtable for MyClass'
home/oak/aeiou/myclass.cpp
collect2: error: Id returned 1 exit status
@And here's my source codes
Add more folders to ship with the application, here
folder_01.source = qml/aeiou
folder_01.target = qml
DEPLOYMENTFOLDERS = folder_01Additional import path used to resolve QML modules in Creator's code model
QML_IMPORT_PATH =
The .cpp file which was generated for your project. Feel free to hack it.
SOURCES += main.cpp
myclass.cppInstallation path
target.path =
Please do not modify the following two lines. Required for deployment.
include(qtquick2applicationviewer/qtquick2applicationviewer.pri)
qtcAddDeployment()HEADERS +=
myclass.h
@myclass.h
@
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QObject>class MyClass : public QObject
{
Q_OBJECTpublic:
MyClass();
void helloMethod(const QString &msg);
};#endif // MYCLASS_H
@main.cpp
@#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include <QtDebug>
#include <QQmlContext>
#include <myclass.h>int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);QtQuick2ApplicationViewer viewer; viewer.rootContext()->setContextProperty("myObject",new MyClass); viewer.setMainQmlFile(QStringLiteral("qml/aeiou/main.qml")); viewer.showExpanded(); return app.exec();
}
@myclass.cpp
@
#include <myclass.h>
#include <QDebug>MyClass::MyClass(){
}void MyClass::helloMethod(const QString &msg) {
qDebug() << "c++ method called " << msg;
}
@main.qml
@
import QtQuick 2.0Rectangle {
width: 100; height: 200
color: "#ad0505"MouseArea { anchors.fill: parent onClicked: { myObject.helloMethod("hi"); }
}
}
@
Thanks for helping newbie : ) -
wrote on 2 Jun 2014, 15:04 last edited by
Oh I finally solved the problem
myclass.h
@
#ifndef MYCLASS_H
#define MYCLASS_H
#include <QObject>class MyClass : public QObject
{
Q_OBJECT
public:
explicit MyClass(QObject *parent = 0);signals:
public slots:
void helloMethod(const QString &msg);
};#endif
@myclass.cpp
@
#include "myclass.h"
#include <QDebug>MyClass::MyClass(QObject *parent) :
QObject(parent)
{
}
void MyClass::helloMethod(const QString &msg) {
qDebug() << "Called the C++ slot with message:" << msg;
}
@
1/2