仅在Qt 5.5中使用RegisterDeviceNotification链接错误
Link error with RegisterDeviceNotification only in Qt 5.5
我升级到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)
我试图在。pro文件中包含模块,但没有任何区别。
根据RegisterDeviceNotification,您需要链接到user32.lib。您可以通过在.pro文件中添加这一行来强制执行:
LIBS += -luser32
然而,这是一个非常常见的Windows库,默认情况下应该链接进来。也许您需要重新运行qmake
以确保您的makefile是最新的?
相关文章:
- 没有找到相关文章