Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. WinEvent in Qt 4.8 and 5

WinEvent in Qt 4.8 and 5

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 9.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    muhahaa
    wrote on last edited by
    #1

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

    It works in 4.8 but doesn't in 5.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      muhahaa
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved