AlphaWolfXV
14th August 2008, 13:36
Hello all,
I have been searching through the QT Assistant and the forums here on events and processing them. I am working on an application where I need to detect when the VID/PID of the device is attached/detached to/from the system. From what I have discovered so far, it would appear as though I can create a class using a QAbstractEventDispatcher and an event filter function referencing a pointer to the received message. Which in the implementation would set the instance thread to 0, i.e. m_EvtDispatch = QAbstractEventDispatcher::instance(0);" and then set event filter, "m_EvtDispatch->setEventFilter(myClass::myEventFilter);"
For the function implementation, it would process the message, maybe as a MSG type (unsure). I have a sample I am working with now as described, and the myEvent loop activates, but the parameters don't seem to ever match DBT_DEVICEARRIVAL/DBT_DEVICEREMOVECOMPLETE/or even DBT_DEVNODES_CHANGED, from the WM_DEVICECHANGE message.
I have searched through the QEvent and QActionEvent and multiple others looking for something close on searching for new devices, but I am kind of at a loss. Any help would be greatly appreciated.
Thanks,
Alphawolfxv
[EDIT 2008-Aug-14]: Should have noted system parameters, QT4.3.3, Win Vista.
[EDIT 2008-Aug-14]: Added code sample.
All these files are trying to do is to break when the WM_DEVICECHANGE is received, I can look for the Attach/Detach once this step is complete, I hope... :o
Header:
#ifndef TESTMSG1_H
#define TESTMSG1_H
#include <QtGui/QDialog>
#include <QAbstractEventDispatcher>
#include <QtDebug>
#include <windows.h>
#include <dbt.h>
class TestMsg : public QDialog
{
Q_OBJECT
public:
TestMsg(QWidget *parent = 0);
~TestMsg();
static bool myEvtFilter(void *message);
private:
QAbstractEventDispatcher * m_EvtDispatch;
};
#endif // TESTMSG1_H
Implementation:
#include "testmsg1.h"
bool TestMsg::myEvtFilter(void *message)
{
MSG *msg;
static int i = 0;
msg = (MSG*)message;
qDebug() << "Test that we are getting events...";
qDebug() << "message: " << msg->message << " wParam: " << msg->wParam
<< " lParam: " << msg->lParam << " handle: " << msg->hwnd;
if (msg->message == WM_DEVICECHANGE)
{
i++;
qDebug() << "Count:" << i << "wParam:" << msg->wParam << "lParam:" << msg-> lParam;
}
return false;
}
TestMsg::TestMsg(QWidget *parent)
: QDialog(parent)
{
m_EvtDispatch = QAbstractEventDispatcher::instance(0);
m_EvtDispatch->setEventFilter(TestMsg::myEvtFilter);
}
TestMsg::~TestMsg()
{
}
I have been searching through the QT Assistant and the forums here on events and processing them. I am working on an application where I need to detect when the VID/PID of the device is attached/detached to/from the system. From what I have discovered so far, it would appear as though I can create a class using a QAbstractEventDispatcher and an event filter function referencing a pointer to the received message. Which in the implementation would set the instance thread to 0, i.e. m_EvtDispatch = QAbstractEventDispatcher::instance(0);" and then set event filter, "m_EvtDispatch->setEventFilter(myClass::myEventFilter);"
For the function implementation, it would process the message, maybe as a MSG type (unsure). I have a sample I am working with now as described, and the myEvent loop activates, but the parameters don't seem to ever match DBT_DEVICEARRIVAL/DBT_DEVICEREMOVECOMPLETE/or even DBT_DEVNODES_CHANGED, from the WM_DEVICECHANGE message.
I have searched through the QEvent and QActionEvent and multiple others looking for something close on searching for new devices, but I am kind of at a loss. Any help would be greatly appreciated.
Thanks,
Alphawolfxv
[EDIT 2008-Aug-14]: Should have noted system parameters, QT4.3.3, Win Vista.
[EDIT 2008-Aug-14]: Added code sample.
All these files are trying to do is to break when the WM_DEVICECHANGE is received, I can look for the Attach/Detach once this step is complete, I hope... :o
Header:
#ifndef TESTMSG1_H
#define TESTMSG1_H
#include <QtGui/QDialog>
#include <QAbstractEventDispatcher>
#include <QtDebug>
#include <windows.h>
#include <dbt.h>
class TestMsg : public QDialog
{
Q_OBJECT
public:
TestMsg(QWidget *parent = 0);
~TestMsg();
static bool myEvtFilter(void *message);
private:
QAbstractEventDispatcher * m_EvtDispatch;
};
#endif // TESTMSG1_H
Implementation:
#include "testmsg1.h"
bool TestMsg::myEvtFilter(void *message)
{
MSG *msg;
static int i = 0;
msg = (MSG*)message;
qDebug() << "Test that we are getting events...";
qDebug() << "message: " << msg->message << " wParam: " << msg->wParam
<< " lParam: " << msg->lParam << " handle: " << msg->hwnd;
if (msg->message == WM_DEVICECHANGE)
{
i++;
qDebug() << "Count:" << i << "wParam:" << msg->wParam << "lParam:" << msg-> lParam;
}
return false;
}
TestMsg::TestMsg(QWidget *parent)
: QDialog(parent)
{
m_EvtDispatch = QAbstractEventDispatcher::instance(0);
m_EvtDispatch->setEventFilter(TestMsg::myEvtFilter);
}
TestMsg::~TestMsg()
{
}