Nominate our 2022 Qt Champions!

Resiving signal from qml

  • i want to receive a string from my qml file...all that i do is copying this two codes from sub url in my program and including libraries...
    "this link!!!":
    but this error occur...
    undefined refrence to 'Vtable fo My class'

    i think its because cpp code line 13-in addressing qml file...
    @// MyItem.qml
    import QtQuick 1.0

    Item {
    id: item
    width: 100; height: 100

     signal qmlSignal(string msg)
     MouseArea {
         anchors.fill: parent
         onClicked: item.qmlSignal("Hello from QML")

    @class MyClass : public QObject
    public slots:
    void cppSlot(const QString &msg) {
    qDebug() << "Called the C++ slot with message:" << msg;

    int main(int argc, char *argv[]) {
    QApplication app(argc, argv);

     QDeclarativeView view(QUrl::fromLocalFile&#40;"MyItem.qml"&#41;);
     QObject *item = view.rootObject();
     MyClass myClass;
     QObject::connect(item, SIGNAL(qmlSignal(QString)),
                      &myClass, SLOT(cppSlot(QString)));
     return app.exec();


    and this is my comple output

    22:00:15: Running build steps for project untitled5...
    22:00:15: Configuration unchanged, skipping qmake step.
    22:00:15: Starting: "C:\Qt\qtcreator-2.4.0\mingw\bin\mingw32-make.exe"
    C:/Qt/qtcreator-2.4.0/mingw/bin/mingw32-make.exe -f Makefile.Debug
    mingw32-make.exe[1]: Entering directory C:/Qt/qtcreator-2.4.0/untitled5-build-desktop-Qt_4_8_0__4_8_0__Debug' g++ -c -g -frtti -fexceptions -mthreads -Wall -DUNICODE -DQT_LARGEFILE_SUPPORT -DQT_DECLARATIVE_DEBUG -DQT_DLL -DQT_DECLARATIVE_LIB -DQT_GUI_LIB -DQT_CORE_LIB -DQT_HAVE_MMX -DQT_HAVE_3DNOW -DQT_HAVE_SSE -DQT_HAVE_MMXEXT -DQT_HAVE_SSE2 -DQT_THREAD_SUPPORT -DQT_NEEDS_QMAIN -I"..\..\4.8.0\include\QtCore" -I"..\..\4.8.0\include\QtGui" -I"..\..\4.8.0\include\QtDeclarative" -I"..\..\4.8.0\include" -I"..\untitled5\qmlapplicationviewer" -I"..\..\4.8.0\include\ActiveQt" -I"debug" -I"..\untitled5" -I"." -I"..\..\4.8.0\mkspecs\win32-g++" -o debug\main.o ..\untitled5\main.cpp g++ -mthreads -Wl,-subsystem,windows -o debug\untitled5.exe debug/main.o debug/qmlapplicationviewer.o debug/moc_qmlapplicationviewer.o -L"c:\Qt\4.8.0\lib" -lmingw32 -lqtmaind -lQtDeclaratived4 -lQtGuid4 -lQtCored4 mingw32-make.exe[1]: Leaving directoryC:/Qt/qtcreator-2.4.0/untitled5-build-desktop-Qt_4_8_0__4_8_0__Debug'
    debug/main.o: In function MyClass': C:\Qt\qtcreator-2.4.0\untitled5-build-desktop-Qt_4_8_0__4_8_0__Debug/../untitled5/main.cpp:5: undefined reference tovtable for MyClass'
    debug/main.o: In function ~MyClass': C:\Qt\qtcreator-2.4.0\untitled5-build-desktop-Qt_4_8_0__4_8_0__Debug/../untitled5/main.cpp:5: undefined reference tovtable for MyClass'
    collect2: ld returned 1 exit status
    mingw32-make.exe[1]: *** [debug\untitled5.exe] Error 1
    mingw32-make.exe: *** [debug] Error 2
    22:00:17: The process "C:\Qt\qtcreator-2.4.0\mingw\bin\mingw32-make.exe" exited with code 2.
    Error while building project untitled5 (target: Desktop)
    When executing build step 'Make'

    i cant fix it!

  • See this thread:

    You'll find it extremely similar and helpful.

    I found it by Googling "undefined reference to `vtable for MyClass’"

    Google == friend

Log in to reply