久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

Qt如何知道新的USB存儲設備何時連接?

How to know when a new USB storage device is connected in Qt?(Qt如何知道新的USB存儲設備何時連接?)
本文介紹了Qt如何知道新的USB存儲設備何時連接?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我想知道 USB 設備何時連接到運行我的 Qt 應用程序的計算機(在 Windows 中).在我的主要 QWidget 中,我重新實現了 winEventFilter,如下所示:

I want to know when a USB device is connected to the computer that my Qt application is running on (in Windows). In my main QWidget, I've reimplemented winEventFilter like this:

bool winEventFilter ( MSG * msg, long * result ) {
    qDebug() << msg;
    return false;
}

當我連接 USB 設備時,我希望 qDebug 至少發送一些東西,但我什么也沒收到.

I'd expect qDebug to send at least something when I connect a USB device, but I don't get anything.

我猜我從根本上誤解了這里的過程 - 這是我的第一個 Qt 應用程序!

I'm guessing that I'm fundamentally misunderstanding the process here - this is my first Qt app!

推薦答案

我相信您可能缺少的是注冊設備通知的調用.這是我用來做同樣事情的代碼,雖然我覆蓋了 QWidget 類的 winEvent() 方法而不是 winEventFilter.

I believe what you may be missing is the call to register for device notification. Here is code that I use to do the same thing, though I override the winEvent() method of the QWidget class and not the winEventFilter.

// Register for device connect notification
DEV_BROADCAST_DEVICEINTERFACE devInt;
ZeroMemory( &devInt, sizeof(devInt) );
devInt.dbcc_size = sizeof(DEV_BROADCAST_DEVICEINTERFACE);
devInt.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE;
devInt.dbcc_classguid = GUID_DEVINTERFACE_VOLUME;

m_hDeviceNotify =
    RegisterDeviceNotification( winId(), &devInt, DEVICE_NOTIFY_WINDOW_HANDLE );   
if(m_hDeviceNotify == NULL)
{
    qDebug() << "Failed to register device notification";
} // end if

注意:您很可能需要更改 DEV_BROADCAST_DEVICEINTERFACE 的值以滿足您的需要.

NOTE: You will most likely need to change the values of the DEV_BROADCAST_DEVICEINTERFACE to fit your needs.

要使用此代碼,您需要包含正確的頭文件并執行正確的設置.DEV_BROADCAST_DEVICEINTERFACE 需要包含 Dbt.h 標頭.此外,此代碼的重點是 RegisterDeviceNotification 函數.信息可在 MSDN

To use this code you will need to include the proper header files and perform the proper setup. DEV_BROADCAST_DEVICEINTERFACE requires the Dbt.h header to be included. Also, the focal point of this code is on the RegisterDeviceNotification function. Info is available on MSDN

這篇關于Qt如何知道新的USB存儲設備何時連接?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 亚洲一区二区电影网 | 91资源在线 | 国产精品久久久久久久久久久免费看 | 涩涩视频网 | 欧美成人一区二免费视频软件 | 福利一区视频 | 亚洲精品中文在线观看 | 国产激情一区二区三区 | 欧美一区二区黄 | 91亚洲国产| 综合九九| av电影手机版 | 在线一区二区国产 | 欧美一区二区三区大片 | 久久人爽爽人爽爽 | 天天干,夜夜操 | 久久精品99国产精品 | 波多野结衣在线观看一区二区三区 | 国产欧美一区二区三区在线看 | 四虎成人精品永久免费av九九 | 午夜寂寞福利视频 | 五月花丁香婷婷 | 国产精品欧美日韩 | 成年人视频在线免费观看 | 国产亚洲精品久久久久久豆腐 | 日韩欧美成人精品 | 一区二区三区在线免费观看视频 | 日批免费观看 | 国产精品久久久久久久久久免费看 | 日本成人久久 | 羞羞色视频| 欧美久久精品一级黑人c片 91免费在线视频 | 欧美黄色录像 | 亚洲欧美一区二区在线观看 | 在线观看av不卡 | 91xxx在线观看 | 日本 欧美 三级 高清 视频 | 四虎成人免费电影 | 国产超碰人人爽人人做人人爱 | 亚洲成人一级 | 欧美精品久久久久 |