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. [SOLVED] Interface class - undefined reference to vtable for MyInterface

[SOLVED] Interface class - undefined reference to vtable for MyInterface

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 11.7k 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.
  • P Offline
    P Offline
    portoist
    wrote on last edited by
    #1

    Hello everyone!
    I'v been trying to create an interface class in my project. Based on this "example":http://doc.qt.nokia.com/4.6/tools-plugandpaint-interfaces-h.html I'v create following class:
    @
    #ifndef IVARIABLE_H
    #define IVARIABLE_H

    #include <QtPlugin>

    class QByteArray;
    class QString;

    class IVariable{
    public:
    virtual ~IVariable(){}
    virtual QString dataId() const;
    virtual void setDataId(QString &dataId);
    virtual QByteArray value() const;
    virtual void setValue(QByteArray &value);
    };
    Q_DECLARE_INTERFACE(IVariable, "my.IVariable/1.0")
    #endif // IVARIABLE_H
    @
    My problem is, that when i try to build my project where o got class Variable that implements such virtual class, I am getting following errors:
    @
    In function '~IVariable': variable.o
    undefined reference to 'vtable for IVariable' ivariable.h 11
    In function 'IVariable': variable.o
    undefined reference to 'vtable for IVariable' ivariable.h 9
    undefined reference to 'typeinfo for IVariable' (.rodata._ZTI8Variable[typeinfo for Variable]+0x18)
    collect2:ld returned 1 exit status
    @
    I am quite new to C++ programing. Could anyone please explain me what am I doing wrong? Thanks a lot!

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on last edited by
      #2

      If you define a real interface, the members must be pure virtual, which means, the yhave no implementation and that must be noted in the header:

      @
      class IVariable{
      public:
      virtual QString dataId() const = 0;
      virtual void setDataId(QString &dataId) = 0;
      virtual QByteArray value() const = 0;
      virtual void setValue(QByteArray &value) = 0;
      virtual void changeValue(QByteArray &value) = 0;
      };
      @

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • P Offline
        P Offline
        portoist
        wrote on last edited by
        #3

        That did the trick! thanks a lot!;-)

        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