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

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

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

問題描述

我想知道 USB 設(shè)備何時連接到運(yùn)行我的 Qt 應(yīng)用程序的計算機(jī)(在 Windows 中).在我的主要 QWidget 中,我重新實(shí)現(xiàn)了 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;
}

當(dāng)我連接 USB 設(shè)備時,我希望 qDebug 至少發(fā)送一些東西,但我什么也沒收到.

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

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

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

推薦答案

我相信您可能缺少的是注冊設(shè)備通知的調(diào)用.這是我用來做同樣事情的代碼,雖然我覆蓋了 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.

要使用此代碼,您需要包含正確的頭文件并執(zhí)行正確的設(shè)置.DEV_BROADCAST_DEVICEINTERFACE 需要包含 Dbt.h 標(biāo)頭.此外,此代碼的重點(diǎn)是 RegisterDeviceNotification 函數(shù).信息可在 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

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

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

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 中文字幕丰满人伦在线 | 少妇视频网站 | 超碰国产在线 | 日韩城人网站 | 青青草在线观看视频 | 这里只有精品视频 | 午夜在线| 亚洲黄色一级 | 国产精品日韩欧美 | 国产中文在线观看 | 国产黄色大片 | 国产免费小视频 | 免费a在线观看 | 永久免费看mv网站入口亚洲 | 日本不卡高字幕在线2019 | 日本精品在线观看 | 亚洲第一免费视频 | a毛片在线观看 | 日韩欧美在线观看视频 | 日韩欧美网站 | 伊人影院久久 | 亚洲黄色在线 | av不卡在线| 黄色一级生活片 | 免费一级大片 | 狠狠操av | 伊人网址 | 亚洲在线观看视频 | 黄色免费小视频 | 久久99精品久久久久久 | 亚洲高清在线 | 一级毛片网 | 在线观看网址你懂的 | 免费国产网站 | 精品国产乱码一区二区三 | 欧美亚洲 | 成人黄色在线 | 国产福利网| 久久久夜色精品 | 久久久夜色精品亚洲 | 成人毛片100免费观看 |