getting that undefined vtable error again
-
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?
-
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?
-
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?
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.
-
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.
@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 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.
If you like, you could do this as well:
class MyNativeEventFilter : public QObject, public QAbstractNativeEventFilter { Q_OBJECT // ... };
-
If you like, you could do this as well:
class MyNativeEventFilter : public QObject, public QAbstractNativeEventFilter { Q_OBJECT // ... };
@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.
-
@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.
-
@mzimmers said in getting that undefined vtable error again:
makes Faulkner look like a comic book
?
-
@JonB perhaps I should have said "Conrad." Baroque, complex, stentorian...while not completely unpleasant, virtually indecipherable.