2010-06-22 46 views

回答

1

研究在您的MainWindow子類中實現winEvent()方法。

#include "Windows.h" 
#include "Dbt.h" 

bool MainWindow::winEvent(MSG *message, long *result) 
{ 
    if (message->message==WM_DEVICECHANGE) 
    { 
     ui->plainTextEdit->appendPlainText("WM_DEVICECHANGE message received"); 
     if (message->wParam==DBT_DEVICEARRIVAL) 
      ui->plainTextEdit->appendPlainText("A new device has arrived"); 
     if (message->wParam==DBT_DEVICEREMOVECOMPLETE) 
      ui->plainTextEdit->appendPlainText("A device has been removed"); 
    } 
    return false; 
} 

我只是測試上述插入我的USB攝像頭到系統並刪除它和我沒有得到適當的輸出看向明文編輯。當然,你應該在Qt文檔中看到有關winEvent()方法的更多信息。 (關於何時從功能返回false或true的信息等)

+0

非常感謝。我或多或少地走在同一條路上。 – 2010-07-12 16:52:08

+0

只是一個簡單的問題。 (我現在是學習者)你是否必須註冊你的應用程序與Windows系統(即RegisterDeviceNotification())我問,因爲我將你的代碼添加到一些教程代碼,我得到一個編譯時錯誤:該過程「 C:/Qt/2010.04/mingw/bin/mingw32-make.exe「用代碼%2退出。 – 2010-07-13 00:29:07

相關問題