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. #if/#endif directives change behaviour of vtable [solved]
Qt 6.11 is out! See what's new in the release blog

#if/#endif directives change behaviour of vtable [solved]

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • 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
    the_scrabi
    wrote on last edited by
    #1

    Can someone explain that to me:

    This code here produces an “undefined reference to vtable” error:
    @
    #ifdef ANDROID
    #ifndef ANDROIDLOGIN_HPP
    #define ANDROIDLOGIN_HPP
    #include <QObject>
    class LoginSystem : public QObject
    {
    Q_OBJECT
    public:
    explicit LoginSystem(QObject *parent = 0);
    signals:
    void accessTokenRceived(QString);
    public slots:
    void login();
    };
    #endif // ANDROIDLOGIN_HPP
    #endif
    @

    While this one works fine:

    @

    #ifndef ANDROIDLOGIN_HPP
    #define ANDROIDLOGIN_HPP
    #include <QObject>
    class LoginSystem : public QObject
    {
    Q_OBJECT
    public:
    explicit LoginSystem(QObject *parent = 0);
    signals:
    void accessTokenRceived(QString);
    public slots:
    void login();
    };
    #endif // ANDROIDLOGIN_HPP

    @

    The strange part is, when the first one is compiled for PC everything works fine. When its compiled for android ld prints out:
    “../tiz/src/facebook/login/androidLogin.cpp:7: error: undefined reference to 'vtable for LoginSystem'”

    What am I doing wrong? Isn't it the sense of the #if/#endif directives to only cut out code? So in case of compiling for android I expected them to behave like they wouldn't be there.

    Also here is the cpp:

    @
    #ifdef ANDROID
    #include "androidLogin.hpp"
    LoginSystem::LoginSystem(QObject *parent) :
    QObject(parent)
    {
    }
    void LoginSystem::login()
    {
    }
    #endif

    @

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      That might be a problem related to moc.

      However in your case rather than "hiding" a class like that, you should only compile it when doing an android build e.g. use the android scope in your pro file, and not build it for the other platforms.

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • T Offline
        T Offline
        the_scrabi
        wrote on last edited by
        #3

        all right thanks

        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