Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Undefined reference to `vtable for MyClass'

Undefined reference to `vtable for MyClass'

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lytze
    wrote on 2 Jun 2014, 10:17 last edited by
    #1

    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 Ubuntu

    Let'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

    aeiou.pro
    @

    Add more folders to ship with the application, here

    folder_01.source = qml/aeiou
    folder_01.target = qml
    DEPLOYMENTFOLDERS = folder_01

    Additional 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.cpp

    Installation 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_OBJECT

    public:
    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&#40;QStringLiteral("qml/aeiou/main.qml"&#41;&#41;;
    viewer.showExpanded();
    return app.exec&#40;&#41;;
    

    }
    @

    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.0

    Rectangle {
    width: 100; height: 200
    color: "#ad0505"

    MouseArea {
    
        anchors.fill: parent
        onClicked: {
            myObject.helloMethod("hi");
    }
    

    }
    }
    @
    Thanks for helping newbie : )

    1 Reply Last reply
    0
    • L Offline
      L Offline
      lytze
      wrote on 2 Jun 2014, 15:04 last edited by
      #2

      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 Reply Last reply
      0

      1/2

      2 Jun 2014, 10:17

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved