What's the standard way of trapping system messages in Qt4?
I've been looking fo开发者_JAVA百科r a way to trap and retrieve system messages in Qt4, specifically the WM_DEVICECHANGE messages among others. I know how to in C# but can find any conclusive text on how to in Qt4. Thanks in advance..
Look into implementing the winEvent() method, say, in your MainWindow subclass.
#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;
}
I just tested the above by inserting my USB video camera into the system and removing it and I did get appropriate looking output into the plaintext edit. You should see further info on the winEvent() method in the Qt docs, of course. (For info on when to return false or true from the function etc)
精彩评论