1

I upgraded to Qt 5.5 and RegisterDeviceNotificationcall started to generate a link error and project doesn't built. It still builds with Qt 5.4 and I am using VS2010 compiler in both cases.

bool MainWindow::nativeEvent(const QByteArray &eventType, void *message, long *result)
{
    MSG * msg = static_cast< MSG * > (message);
    int msgType = msg->message;
    if(msgType == WM_PAINT)
    {
        if(!msgp)   //Only the first WM_PAINT
        {
            GUID InterfaceClassGuid = HID_CLASSGUID;
            DEV_BROADCAST_DEVICEINTERFACE NotificationFilter;
            ZeroMemory( &NotificationFilter, sizeof(NotificationFilter) );
            NotificationFilter.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
            NotificationFilter.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
            NotificationFilter.dbcc_classguid = InterfaceClassGuid;
            HWND hw = (HWND) this->effectiveWinId();   //Main window handle
            HDEVNOTIFY hDevNotify = RegisterDeviceNotification(hw,&NotificationFilter, DEVICE_NOTIFY_ALL_INTERFACE_CLASSES ); //DEVICE_NOTIFY_WINDOW_HANDLE);
            msgp = true;
        }
    }
    // i have more code here but the link error occurs in the above
}

I did include <windows.h> and <WinUser.h> but that didn't fix the link error.

The link error is:

mainwindow.obj:-1: error: LNK2019: unresolved external symbol __imp__RegisterDeviceNotificationW@12 referenced in function "private: virtual bool __thiscall MainWindow::nativeEvent(class QByteArray const &,void *,long *)" (?nativeEvent@MainWindow@@EAE_NABVQByteArray@@PAXPAJ@Z)

I tried to include modules in .pro files from here but none has made any difference.

zar
  • 11,361
  • 14
  • 96
  • 178
  • possible duplicate of [What is an undefined reference/unresolved external symbol error and how do I fix it?](http://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – IInspectable Aug 25 '15 at 18:15

1 Answers1

3

According to RegisterDeviceNotification, you need to link with user32.lib. You can force this by adding this line to your .pro file:

LIBS += -luser32

However, this is a quite common Windows library that should have been linked in by default. Maybe you need to re-run qmake to ensure your makefiles are up to date?

David Ching
  • 1,903
  • 17
  • 21
  • Thanks! I did run `qmake` so many times, cleaned project and deletet built directory but only including this manually did the trick! – zar Aug 25 '15 at 17:22