Results 1 to 10 of 10

Thread: systemwide hotkey

  1. #1
    Join Date
    Jul 2009
    Posts
    8
    Platforms
    Windows

    Question systemwide hotkey

    Hi,
    I'm trying to use a systemwide hotkey, to open some windows from an application, running in background.

    I read that Qt doesn't support this systemwide hotkeys itself, so I tried doing something with registerhotkey. What i tried is:

    In the constructor of a dialog form, i put
    Qt Code:
    1. RegisterHotKey(winId(), 100, MOD_CONTROL, VK_SPACE);
    To copy to clipboard, switch view to plain text mode 

    And i used this function, just for testing if any event gets reported to my app

    Qt Code:
    1. bool winEvent(MSG * m)
    2. {
    3. QApplication::quit();
    4. return false;
    5. }
    To copy to clipboard, switch view to plain text mode 

    But it seems that there is never reported an event.

    Where's my mistake? Maybe I understood sth. Wrong, how does this work?

    Thanks.

  2. #2
    Join Date
    Jul 2009
    Posts
    8
    Platforms
    Windows

    Default Re: systemwide hotkey

    does anyone has an idea? i was looking for a solution for >5 hours now... can't find anything....

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: systemwide hotkey

    J-P Nurmi

  4. #4
    Join Date
    Jul 2009
    Posts
    8
    Platforms
    Windows

    Default Re: systemwide hotkey

    well, thanks, i was playing around with that for the last 4 hours, but i don't get it to work...

    Maybe you could tell me whats wrong with this:

    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include <QxtApplication>
    3.  
    4. int main(int argc, char *argv[])
    5. {
    6. QxtApplication a(argc, argv);
    7. MainWindow w;
    8. w.show();
    9. return a.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 


    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QtGui/QMainWindow>
    5. #include <QxtApplication>
    6. #include <QxtGlobalShortcut>
    7.  
    8. namespace Ui
    9. {
    10. class MainWindow;
    11. }
    12.  
    13. class MainWindow : public QMainWindow
    14. {
    15. Q_OBJECT
    16. QxtGlobalShortcut *m_action;
    17.  
    18. public:
    19. MainWindow(QWidget *parent = 0);
    20. ~MainWindow();
    21.  
    22. public slots:
    23. void jump();
    24. private:
    25. Ui::MainWindow *ui;
    26. };
    27.  
    28. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    and mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "ui_mainwindow.h"
    3. #include <QxtApplication>
    4. #include <QxtGlobalShortcut>
    5. #include <QDebug>
    6. MainWindow::MainWindow(QWidget *parent)
    7. : QMainWindow(parent), ui(new Ui::MainWindow), m_action(new QxtGlobalShortcut(QKeySequence("Ctrl+Alt+A")))
    8. {
    9. ui->setupUi(this);
    10. connect(m_action, SIGNAL(activated()), this, SLOT(jump()));
    11. }
    12.  
    13. MainWindow::~MainWindow()
    14. {
    15. delete ui;
    16. }
    17.  
    18. void MainWindow::jump()
    19. {
    20. qDebug() << "Jump!";
    21. }
    To copy to clipboard, switch view to plain text mode 


    The Problem is:
    When i start the program (compiling works fine), the application closes, and windows tells me something like "....exe isn't working anymore..." [sorry, i don't know the exakt message in english, that's the translation of the german message]

    Doe's anyone know what I did wrong?

    (I'm using QtCreator..)

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: systemwide hotkey

    This could be caused by the famous release vs. debug mix on Windows. Make sure you compile your app in the same mode as Qxt was built.
    J-P Nurmi

  6. #6
    Join Date
    Jul 2009
    Posts
    8
    Platforms
    Windows

    Default Re: systemwide hotkey

    no, thats not the problem.
    I first build Qxt wrong, but at this time i couldn't even compile the project. After that i compiled it for debug mode, and my project also runs in debug mode. (i also tried release mode, but doesn't help)

    Any other ideas?

  7. #7
    Join Date
    Jul 2009
    Posts
    8
    Platforms
    Windows

    Default Re: systemwide hotkey

    I'm still interestet in an solution for this. If it doesn't work like this, i'd also be glad for another possibility to do this. (It only has to work in windows!)

  8. #8
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: systemwide hotkey

    Have you tried rebuilding both Qxt and your application from clean, making sure both are built in the same mode? I'd still claim that's the problem. I've seen that problem sooo many times.
    J-P Nurmi

  9. #9
    Join Date
    Jul 2009
    Posts
    8
    Platforms
    Windows

    Default Re: systemwide hotkey

    yes i did, but it didn't help

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: systemwide hotkey

    Then I guess you have to use a debugger to see where it goes wrong. Preferably attach a minimal compilable test case that reproduces the problem and the corresponding backtrace from a debugger.

    PS. Does the QxtGui test application work for you? It's in tests/other/app.
    J-P Nurmi

Similar Threads

  1. How to realize the hotKey function?
    By cspp in forum Qt Programming
    Replies: 1
    Last Post: 1st July 2009, 11:12
  2. systemwide user profiles
    By luf in forum Qt Programming
    Replies: 0
    Last Post: 6th August 2008, 14:12
  3. Setting Hotkey Shortcuts
    By VireX in forum Newbie
    Replies: 8
    Last Post: 4th April 2007, 22:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.