Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved getting that undefined vtable error again

    General and Desktop
    3
    9
    249
    Loading More Posts
    • 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.
    • mzimmers
      mzimmers last edited by 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?

      JonB kshegunov 2 Replies Last reply Reply Quote 0
      • JonB
        JonB @mzimmers last edited by JonB

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

        1 Reply Last reply Reply Quote 3
        • kshegunov
          kshegunov Moderators @mzimmers last edited by 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.

          Read and abide by the Qt Code of Conduct

          mzimmers 1 Reply Last reply Reply Quote 3
          • mzimmers
            mzimmers @kshegunov last edited by

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

            kshegunov 1 Reply Last reply Reply Quote 1
            • kshegunov
              kshegunov Moderators @mzimmers last edited by kshegunov

              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

              mzimmers 1 Reply Last reply Reply Quote 4
              • mzimmers
                mzimmers @kshegunov last edited by

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

                JonB 1 Reply Last reply Reply Quote 1
                • JonB
                  JonB @mzimmers last edited by

                  @mzimmers said in getting that undefined vtable error again:

                  makes Faulkner look like a comic book

                  ?

                  mzimmers 1 Reply Last reply Reply Quote 0
                  • mzimmers
                    mzimmers @JonB last edited by

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

                    JonB 1 Reply Last reply Reply Quote 0
                    • JonB
                      JonB @mzimmers last edited by

                      @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 Reply Quote 0
                      • First post
                        Last post