I've been looking for 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..
+1
A:
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)
Xenakios
2010-07-05 11:50:28
Thank you very much. I was more or less on the same path.
Dark Star1
2010-07-12 16:52:08
Just a quick question. (I'm a learner at the moment) Did you have to register your app with windows system (i.e. RegisterDeviceNotification() ) I ask because I added your code to some tutorial code and I'm getting a compile time error: The process "C:/Qt/2010.04/mingw/bin/mingw32-make.exe" exited with code %2.
Dark Star1
2010-07-13 00:29:07