getting that undefined vtable error again
-
wrote on 4 Oct 2020, 18:50 last edited by mzimmers 10 Apr 2020, 18:57
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?
wrote on 4 Oct 2020, 20:25 last edited by JonB 10 Apr 2020, 20:25@mzimmers
It is not. Look at https://doc.qt.io/qt-5/qabstractnativeeventfilter.html. -
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?
Moderatorswrote on 4 Oct 2020, 23:01 last edited by kshegunov 10 Apr 2020, 23:04Besides 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.
wrote on 4 Oct 2020, 23:19 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 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.
Moderatorswrote on 4 Oct 2020, 23:21 last edited by kshegunov 10 Apr 2020, 23:22If 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 // ... };
wrote on 4 Oct 2020, 23:40 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.
-
@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.
wrote on 5 Oct 2020, 19:07 last edited by@mzimmers said in getting that undefined vtable error again:
makes Faulkner look like a comic book
?
-
@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.
8/9