jonks
9th August 2010, 06:06
Hi,
Is there anything wrong with this code?
It outputs all events the application receives.
I'm trying to get an application to accept drag events that originate from a different application. I noticed that my dragEnterEvent was not being called.
I wrote a minimal application (see below) to test.
The weird thing is I just upgraded from 4.6.1 to 4.6.3 and an application that used to received dragEnterEvent stopped doing so immediately. But I'm not sure right now if that is a co-incidence (I've been changing some code unrelated to DnD).
Here's the minimal project:
Header:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
protected:
bool eventFilter(QObject* o,QEvent* e);
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
CPP file:
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qApp->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::eventFilter(QObject* o,QEvent* e)
{
qDebug() << e->type() << o; // e->type is never 60 (QEvent::DragEnter)
if(e->type()==QEvent::DragEnter)
qDebug() << "QEvent::DragEnter"; // THIS IS NEVER OUTPUT
return false;
}
Is there anything wrong with this code?
It outputs all events the application receives.
I'm trying to get an application to accept drag events that originate from a different application. I noticed that my dragEnterEvent was not being called.
I wrote a minimal application (see below) to test.
The weird thing is I just upgraded from 4.6.1 to 4.6.3 and an application that used to received dragEnterEvent stopped doing so immediately. But I'm not sure right now if that is a co-incidence (I've been changing some code unrelated to DnD).
Here's the minimal project:
Header:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
protected:
bool eventFilter(QObject* o,QEvent* e);
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
CPP file:
#include <QDebug>
#include "mainwindow.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
qApp->installEventFilter(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
bool MainWindow::eventFilter(QObject* o,QEvent* e)
{
qDebug() << e->type() << o; // e->type is never 60 (QEvent::DragEnter)
if(e->type()==QEvent::DragEnter)
qDebug() << "QEvent::DragEnter"; // THIS IS NEVER OUTPUT
return false;
}