WinEvent in Qt 4.8 and 5



  • What changes were made to winEvent from Qt4.8 to Qt5.0.1?

    It works in 4.8 but doesn't in 5.



  • Test code:

    @#ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

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


  • Moderators

    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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.