Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. convert c++ class to qt class
Forum Updated to NodeBB v4.3 + New Features

convert c++ class to qt class

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.3k 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.
  • T Offline
    T Offline
    tony67
    wrote on last edited by
    #1

    Hi All,
    hope someone can help with this. There's a c++ class in my qt code that I need to turn into a qt class ( sorry don't know correct term ). As I need to pass a signal from it. I've tried but get some errors to do with "vtables".
    What I did was add #include <QObject> to my class header, changed the way the class is declared and the way the constructor is declared so in header I've replaced
    [code]
    class Bonus_Class
    {
    public:
    Bonus_Class();
    [/code]
    with
    [code]
    class Bonus_Class : public QObject
    {
    Q_OBJECT
    public:

    explicit Bonus_Class(QObject *parent = 0);
    

    [/code]
    then I've replace the constructor in my code with
    [code]
    //Bonus_Class::Bonus_Class()
    //{
    //}

    Bonus_Class::Bonus_Class(QObject *parent) :QObject(parent)
    {

    }

    [/code]

    However this gives a vtable error, not sure what this is.
    [code]
    /bonus_class.cpp:11: error: undefined reference to vtable for Bonus_Class' /bonus_class.h:95: error: undefined reference to vtable for Bonus_Class'
    [/code]

    can anyone advise, I'm sure this is simple but I'm not used to QT. Thanks

    1 Reply Last reply
    0
    • D Offline
      D Offline
      ddze
      wrote on last edited by ddze
      #2

      Try to run qMake , than rebuild.

      1 Reply Last reply
      1
      • jsulmJ Offline
        jsulmJ Offline
        jsulm
        Lifetime Qt Champion
        wrote on last edited by
        #3

        No need to change the constructor if your class does not need a parent.
        Run qmake and rebuild your project.

        https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        1
        • T Offline
          T Offline
          tony67
          wrote on last edited by
          #4

          Thankyou all qmake worked

          1 Reply Last reply
          0

          • Login

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