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
Forum Updated to NodeBB v4.3 + New Features

getting that undefined vtable error again

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 3 Posters 662 Views 2 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 4 Oct 2020, 18:50 last edited by mzimmers 10 Apr 2020, 18:57
    #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?

    J K 2 Replies Last reply 4 Oct 2020, 20:25
    0
    • M mzimmers
      4 Oct 2020, 18:50

      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?

      J Online
      J Online
      JonB
      wrote on 4 Oct 2020, 20:25 last edited by JonB 10 Apr 2020, 20:25
      #2

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

      1 Reply Last reply
      3
      • M mzimmers
        4 Oct 2020, 18:50

        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?

        K Offline
        K Offline
        kshegunov
        Moderators
        wrote on 4 Oct 2020, 23:01 last edited by kshegunov 10 Apr 2020, 23:04
        #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

        M 1 Reply Last reply 4 Oct 2020, 23:19
        3
        • K kshegunov
          4 Oct 2020, 23:01

          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.

          M Offline
          M Offline
          mzimmers
          wrote on 4 Oct 2020, 23:19 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.

          K 1 Reply Last reply 4 Oct 2020, 23:21
          1
          • M mzimmers
            4 Oct 2020, 23:19

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

            K Offline
            K Offline
            kshegunov
            Moderators
            wrote on 4 Oct 2020, 23:21 last edited by kshegunov 10 Apr 2020, 23:22
            #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

            M 1 Reply Last reply 4 Oct 2020, 23:40
            4
            • K kshegunov
              4 Oct 2020, 23:21

              If you like, you could do this as well:

              class MyNativeEventFilter : public QObject, public QAbstractNativeEventFilter
              {
                  Q_OBJECT
                  // ...
              };
              
              M Offline
              M Offline
              mzimmers
              wrote on 4 Oct 2020, 23:40 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.

              J 1 Reply Last reply 5 Oct 2020, 19:07
              1
              • M mzimmers
                4 Oct 2020, 23:40

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

                J Online
                J Online
                JonB
                wrote on 5 Oct 2020, 19:07 last edited by
                #7

                @mzimmers said in getting that undefined vtable error again:

                makes Faulkner look like a comic book

                ?

                M 1 Reply Last reply 5 Oct 2020, 19:19
                0
                • J JonB
                  5 Oct 2020, 19:07

                  @mzimmers said in getting that undefined vtable error again:

                  makes Faulkner look like a comic book

                  ?

                  M Offline
                  M Offline
                  mzimmers
                  wrote on 5 Oct 2020, 19:19 last edited by
                  #8

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

                  J 1 Reply Last reply 5 Oct 2020, 19:22
                  0
                  • M mzimmers
                    5 Oct 2020, 19:19

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

                    J Online
                    J Online
                    JonB
                    wrote on 5 Oct 2020, 19:22 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

                    8/9

                    5 Oct 2020, 19:19

                    • Login

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