Results 1 to 2 of 2

Thread: help with QAbstractNativeEventFilter

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2013
    Posts
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question help with QAbstractNativeEventFilter

    hi,

    i am trying to catch native events on the windows platform, to communicate with an hid usb device.... i have successfully done so using the nativeEvent method in QWidget....now i am trying to create a generic class that can be added to any QWidget or QMainWindow.

    for this pupose i am trying to derive a class from QAbstractNativeEventFilter .... Override the virtual nativeEventFilter and instantiate this class in the QWidget of my choice....yet i am unable to recieve any events so far.....

    i am new to qt and havent had much experience using abstract classes.....i am attaching a sample below....using this example the code compiles and the widget window appears but the nativeeventfilter method is not called. any help would be highly appreciated.....

    usbworker.h
    Qt Code:
    1. #ifndef USBWORKER_H
    2. #define USBWORKER_H
    3.  
    4. #include <QAbstractNativeEventFilter>
    5.  
    6. class usbworker : public QAbstractNativeEventFilter
    7. {
    8. public:
    9. usbworker();
    10. virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
    11.  
    12. };
    13.  
    14. #endif // USBWORKER_H
    To copy to clipboard, switch view to plain text mode 

    usbworker.cpp
    Qt Code:
    1. #include "usbworker.h"
    2.  
    3. usbworker::usbworker()
    4. {
    5.  
    6. }
    7.  
    8.  
    9. bool usbworker::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
    10. Q_DECL_OVERRIDE
    11. {
    12. qDebug("i came here");
    13. return false;
    14. }
    To copy to clipboard, switch view to plain text mode 

    widget.h
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QWidget>
    5. #include <usbworker.h>
    6.  
    7. namespace Ui {
    8. class Widget;
    9. }
    10.  
    11. class Widget : public QWidget
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. explicit Widget(QWidget *parent = 0);
    17. ~Widget();
    18. usbworker uw;
    19.  
    20. private:
    21. Ui::Widget *ui;
    22. };
    23.  
    24. #endif // WIDGET_H
    To copy to clipboard, switch view to plain text mode 

    widget.cpp
    Qt Code:
    1. #include "widget.h"
    2. #include "ui_widget.h"
    3.  
    4.  
    5. Widget::Widget(QWidget *parent) :
    6. QWidget(parent),
    7. ui(new Ui::Widget)
    8. {
    9. ui->setupUi(this);
    10. }
    11.  
    12. Widget::~Widget()
    13. {
    14. delete ui;
    15. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include "widget.h"
    2. #include <QApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QApplication a(argc, argv);
    7. Widget w;
    8. w.show();
    9.  
    10. return a.exec();
    11. }
    To copy to clipboard, switch view to plain text mode 

    i am using qt 5.1.0
    Last edited by alee; 2nd October 2013 at 20:14. Reason: updated contents

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
  •  
Qt is a trademark of The Qt Company.