WinEvent in Qt 4.8 and 5
-
Test code:
@#ifndef MAINWINDOW_H
#define MAINWINDOW_H#include <QMainWindow>
namespace Ui {
class MainWindow;
}class MainWindow : public QMainWindow
{
Q_OBJECTpublic:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();protected:
bool winEvent(MSG *message, long *result);private:
Ui::MainWindow *ui;
};#endif // MAINWINDOW_H
@@#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <Windows.h>
#include <QMessageBox>
#pragma comment(lib, "user32.lib")MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
if(RegisterHotKey((HWND)winId(), 1, 0, VK_F6))
{
QMessageBox::information(0, "", "Hotkey registered");
}
else
{
QMessageBox::information(0, "", "Failed to register hotkey");
}
}MainWindow::~MainWindow()
{
delete ui;
}bool MainWindow::winEvent(MSG *message, long *result)
{
if (message->message == WM_HOTKEY)
{
QMessageBox::information(0, "", "Hotkey pressed");
}
return false;
}
@If I press F6 in the 4.8 build, it works. In the 5.0.1 build it doesn't.
-
winEvent (and other platform specific events) was removed and the functionality is available through "nativeEvent":http://qt-project.org/doc/qt-5.0/qtwidgets/qwidget.html#nativeEvent