Results 1 to 4 of 4

Thread: USB Win Events messages Detecting in QT

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Aug 2008
    Posts
    38
    Thanks
    15
    Qt products
    Qt4
    Platforms
    Windows

    Default USB Win Events messages Detecting in QT

    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...

    Header:
    Qt Code:
    1. #ifndef TESTMSG1_H
    2. #define TESTMSG1_H
    3.  
    4. #include <QtGui/QDialog>
    5. #include <QAbstractEventDispatcher>
    6. #include <QtDebug>
    7. #include <windows.h>
    8. #include <dbt.h>
    9.  
    10. class TestMsg : public QDialog
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. TestMsg(QWidget *parent = 0);
    16. ~TestMsg();
    17.  
    18. static bool myEvtFilter(void *message);
    19.  
    20. private:
    21. QAbstractEventDispatcher * m_EvtDispatch;
    22. };
    23.  
    24. #endif // TESTMSG1_H
    To copy to clipboard, switch view to plain text mode 

    Implementation:

    Qt Code:
    1. #include "testmsg1.h"
    2.  
    3. bool TestMsg::myEvtFilter(void *message)
    4. {
    5. MSG *msg;
    6. static int i = 0;
    7.  
    8. msg = (MSG*)message;
    9. qDebug() << "Test that we are getting events...";
    10. qDebug() << "message: " << msg->message << " wParam: " << msg->wParam
    11. << " lParam: " << msg->lParam << " handle: " << msg->hwnd;
    12. if (msg->message == WM_DEVICECHANGE)
    13. {
    14. i++;
    15. qDebug() << "Count:" << i << "wParam:" << msg->wParam << "lParam:" << msg-> lParam;
    16. }
    17.  
    18. return false;
    19. }
    20.  
    21.  
    22. TestMsg::TestMsg(QWidget *parent)
    23. : QDialog(parent)
    24. {
    25.  
    26. m_EvtDispatch = QAbstractEventDispatcher::instance(0);
    27. m_EvtDispatch->setEventFilter(TestMsg::myEvtFilter);
    28. }
    29.  
    30. TestMsg::~TestMsg()
    31. {
    32.  
    33. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by AlphaWolfXV; 14th August 2008 at 15:58.

Similar Threads

  1. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 15:03
  2. Detecting KeyPad Events from my Keypad
    By Svaths in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 18th August 2006, 07:28

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.