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. getting that undefined vtable error again

getting that undefined vtable error again

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 645 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by mzimmers
    #1

    Hi all -

    This came up as the result of another thread, but I think it warrants its own thread. This code:

    class MyNativeEventFilter: public QAbstractNativeEventFilter
    {
        Q_OBJECT
    private:
    public:
         bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)
        Q_DECL_OVERRIDE
        {
            Q_UNUSED(eventType) // unneeded as long as we're only running on Windows
            Q_UNUSED(result)
            MSG *msg = (MSG *)(message);
    
            if ((msg->message == WM_DEVICECHANGE)
               && (msg->wParam == DBT_DEVNODES_CHANGED))
            {
                emit notify();
            }
            return false;
        }
    Q_SIGNALS:
        void notify();
    };
    

    gives me this

    C:\wifibutton\build-wifibutton_utility-Desktop_Qt_5_15_0_MinGW_32_bit-Debug\..\utility\main.cpp:19: 
    error: undefined reference to `vtable for MyNativeEventFilter'
    

    The error goes away when I comment out the emit() statement. What causes this, and what am I doing wrong here?

    Thanks...

    EDIT:

    Disregard the statement that it works without the emit(): I have to remove the signal declaration AND Q_OBJECT to get it to compile. So...do I correctly infer that QAbstractNativeEventFilter is not derived from QObject?

    JonBJ kshegunovK 2 Replies Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      This came up as the result of another thread, but I think it warrants its own thread. This code:

      class MyNativeEventFilter: public QAbstractNativeEventFilter
      {
          Q_OBJECT
      private:
      public:
           bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)
          Q_DECL_OVERRIDE
          {
              Q_UNUSED(eventType) // unneeded as long as we're only running on Windows
              Q_UNUSED(result)
              MSG *msg = (MSG *)(message);
      
              if ((msg->message == WM_DEVICECHANGE)
                 && (msg->wParam == DBT_DEVNODES_CHANGED))
              {
                  emit notify();
              }
              return false;
          }
      Q_SIGNALS:
          void notify();
      };
      

      gives me this

      C:\wifibutton\build-wifibutton_utility-Desktop_Qt_5_15_0_MinGW_32_bit-Debug\..\utility\main.cpp:19: 
      error: undefined reference to `vtable for MyNativeEventFilter'
      

      The error goes away when I comment out the emit() statement. What causes this, and what am I doing wrong here?

      Thanks...

      EDIT:

      Disregard the statement that it works without the emit(): I have to remove the signal declaration AND Q_OBJECT to get it to compile. So...do I correctly infer that QAbstractNativeEventFilter is not derived from QObject?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @mzimmers
      It is not. Look at https://doc.qt.io/qt-5/qabstractnativeeventfilter.html.

      1 Reply Last reply
      3
      • mzimmersM mzimmers

        Hi all -

        This came up as the result of another thread, but I think it warrants its own thread. This code:

        class MyNativeEventFilter: public QAbstractNativeEventFilter
        {
            Q_OBJECT
        private:
        public:
             bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)
            Q_DECL_OVERRIDE
            {
                Q_UNUSED(eventType) // unneeded as long as we're only running on Windows
                Q_UNUSED(result)
                MSG *msg = (MSG *)(message);
        
                if ((msg->message == WM_DEVICECHANGE)
                   && (msg->wParam == DBT_DEVNODES_CHANGED))
                {
                    emit notify();
                }
                return false;
            }
        Q_SIGNALS:
            void notify();
        };
        

        gives me this

        C:\wifibutton\build-wifibutton_utility-Desktop_Qt_5_15_0_MinGW_32_bit-Debug\..\utility\main.cpp:19: 
        error: undefined reference to `vtable for MyNativeEventFilter'
        

        The error goes away when I comment out the emit() statement. What causes this, and what am I doing wrong here?

        Thanks...

        EDIT:

        Disregard the statement that it works without the emit(): I have to remove the signal declaration AND Q_OBJECT to get it to compile. So...do I correctly infer that QAbstractNativeEventFilter is not derived from QObject?

        kshegunovK Offline
        kshegunovK Offline
        kshegunov
        Moderators
        wrote on last edited by kshegunov
        #3

        Besides what @JonB sourced, and assuming the error persists (if we are talking *nix), put a non inlined trivial constructor before the first virtual and then recompile, should go away.

        PS: Also for the love of god don't put virtual implementations inside the class declaration, the style being ugly and cluttering the interface notwithstanding, the compiler can't, and hence never will, inline them, so there's no performance gain even.

        Read and abide by the Qt Code of Conduct

        mzimmersM 1 Reply Last reply
        3
        • kshegunovK kshegunov

          Besides what @JonB sourced, and assuming the error persists (if we are talking *nix), put a non inlined trivial constructor before the first virtual and then recompile, should go away.

          PS: Also for the love of god don't put virtual implementations inside the class declaration, the style being ugly and cluttering the interface notwithstanding, the compiler can't, and hence never will, inline them, so there's no performance gain even.

          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #4

          @kshegunov thanks for the suggestions. This isn't *nix, so I just created an intermediary class to handle the signal:

          class MySignal: public QObject
          {
              Q_OBJECT
          public:
              void notify() { emit sendSignal(); }
          Q_SIGNALS:
              void sendSignal();
          };
          
          class MyNativeEventFilter: public QAbstractNativeEventFilter
          {
          private:
              MySignal mySignal;
          public:
              MyNativeEventFilter(QObject *parent);
              bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)
              Q_DECL_OVERRIDE;
          };
          bool MyNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
          {
              Q_UNUSED(eventType) // unneeded as long as we're only running on Windows
              Q_UNUSED(result)
              MSG *msg = (MSG *)(message);
          
              if ((msg->message == WM_DEVICECHANGE)
                      && (msg->wParam == DBT_DEVNODES_CHANGED))
              {
                  mySignal.notify();
              }
              return false;
          }
          

          This appears to work, and I think is about as straightforward as I'm going to get it.

          kshegunovK 1 Reply Last reply
          1
          • mzimmersM mzimmers

            @kshegunov thanks for the suggestions. This isn't *nix, so I just created an intermediary class to handle the signal:

            class MySignal: public QObject
            {
                Q_OBJECT
            public:
                void notify() { emit sendSignal(); }
            Q_SIGNALS:
                void sendSignal();
            };
            
            class MyNativeEventFilter: public QAbstractNativeEventFilter
            {
            private:
                MySignal mySignal;
            public:
                MyNativeEventFilter(QObject *parent);
                bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)
                Q_DECL_OVERRIDE;
            };
            bool MyNativeEventFilter::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
            {
                Q_UNUSED(eventType) // unneeded as long as we're only running on Windows
                Q_UNUSED(result)
                MSG *msg = (MSG *)(message);
            
                if ((msg->message == WM_DEVICECHANGE)
                        && (msg->wParam == DBT_DEVNODES_CHANGED))
                {
                    mySignal.notify();
                }
                return false;
            }
            

            This appears to work, and I think is about as straightforward as I'm going to get it.

            kshegunovK Offline
            kshegunovK Offline
            kshegunov
            Moderators
            wrote on last edited by kshegunov
            #5

            If you like, you could do this as well:

            class MyNativeEventFilter : public QObject, public QAbstractNativeEventFilter
            {
                Q_OBJECT
                // ...
            };
            

            Read and abide by the Qt Code of Conduct

            mzimmersM 1 Reply Last reply
            4
            • kshegunovK kshegunov

              If you like, you could do this as well:

              class MyNativeEventFilter : public QObject, public QAbstractNativeEventFilter
              {
                  Q_OBJECT
                  // ...
              };
              
              mzimmersM Offline
              mzimmersM Offline
              mzimmers
              wrote on last edited by
              #6

              @kshegunov that's a winner. Thanks!

              It appears that I can derive additional information by making some other OS calls (eg RegisterDeviceNotificationA()), but honestly the MS documentation makes Faulkner look like a comic book, and I don't think it's worth it. When I get such an event, I'll just re-poll for devices.

              JonBJ 1 Reply Last reply
              1
              • mzimmersM mzimmers

                @kshegunov that's a winner. Thanks!

                It appears that I can derive additional information by making some other OS calls (eg RegisterDeviceNotificationA()), but honestly the MS documentation makes Faulkner look like a comic book, and I don't think it's worth it. When I get such an event, I'll just re-poll for devices.

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #7

                @mzimmers said in getting that undefined vtable error again:

                makes Faulkner look like a comic book

                ?

                mzimmersM 1 Reply Last reply
                0
                • JonBJ JonB

                  @mzimmers said in getting that undefined vtable error again:

                  makes Faulkner look like a comic book

                  ?

                  mzimmersM Offline
                  mzimmersM Offline
                  mzimmers
                  wrote on last edited by
                  #8

                  @JonB perhaps I should have said "Conrad." Baroque, complex, stentorian...while not completely unpleasant, virtually indecipherable.

                  JonBJ 1 Reply Last reply
                  0
                  • mzimmersM mzimmers

                    @JonB perhaps I should have said "Conrad." Baroque, complex, stentorian...while not completely unpleasant, virtually indecipherable.

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #9

                    @mzimmers
                    Oh! This is a bit advanced for me! I only recently discovered you are American. We don't do Faulkner. "Stentorian" --- do you really expect me to know what means without looking it up? :)

                    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