我升级到Qt 5.5并且RegisterDeviceNotification
调用已启动以生成链接错误,并且项目未构建。它仍然使用Qt 5.4构建,我在两种情况下都使用VS2010编译器。
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
}
我确实包含了<windows.h>
和<WinUser.h>
,但这并没有解决链接错误。
链接错误是:
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)
我试图在here的.pro文件中包含模块,但没有任何区别。
答案 0 :(得分:2)
根据RegisterDeviceNotification,您需要链接user32.lib。您可以通过将此行添加到.pro文件来强制执行此操作:
LIBS += -luser32
但是,这是一个非常常见的Windows库,默认情况下应该已经链接。也许您需要重新运行qmake
以确保您的makefile是最新的?