alee
2nd October 2013, 19:48
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
#ifndef USBWORKER_H
#define USBWORKER_H
#include <QAbstractNativeEventFilter>
class usbworker : public QAbstractNativeEventFilter
{
public:
usbworker();
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
};
#endif // USBWORKER_H
usbworker.cpp
#include "usbworker.h"
usbworker::usbworker()
{
}
bool usbworker::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
Q_DECL_OVERRIDE
{
qDebug("i came here");
return false;
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <usbworker.h>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
usbworker uw;
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
i am using qt 5.1.0
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
#ifndef USBWORKER_H
#define USBWORKER_H
#include <QAbstractNativeEventFilter>
class usbworker : public QAbstractNativeEventFilter
{
public:
usbworker();
virtual bool nativeEventFilter(const QByteArray &eventType, void *message, long *result);
};
#endif // USBWORKER_H
usbworker.cpp
#include "usbworker.h"
usbworker::usbworker()
{
}
bool usbworker::nativeEventFilter(const QByteArray &eventType, void *message, long *result)
Q_DECL_OVERRIDE
{
qDebug("i came here");
return false;
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <usbworker.h>
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
usbworker uw;
private:
Ui::Widget *ui;
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include "ui_widget.h"
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
}
Widget::~Widget()
{
delete ui;
}
main.cpp
#include "widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
i am using qt 5.1.0