PDA

View Full Version : systemwide hotkey



Screeze
5th July 2009, 16:15
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

RegisterHotKey(winId(), 100, MOD_CONTROL, VK_SPACE);

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



bool winEvent(MSG * m)
{
QApplication::quit();
return false;
}


But it seems that there is never reported an event.

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

Thanks.

Screeze
6th July 2009, 10:39
does anyone has an idea? i was looking for a solution for >5 hours now... can't find anything....

jpn
6th July 2009, 20:09
See QxtGlobalShortcut (http://doc.libqxt.org/tip/classQxtGlobalShortcut.html).

Screeze
7th July 2009, 18:20
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

#include "mainwindow.h"
#include <QxtApplication>

int main(int argc, char *argv[])
{
QxtApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}



mainwindow.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QtGui/QMainWindow>
#include <QxtApplication>
#include <QxtGlobalShortcut>

namespace Ui
{
class MainWindow;
}

class MainWindow : public QMainWindow
{
Q_OBJECT
QxtGlobalShortcut *m_action;

public:
MainWindow(QWidget *parent = 0);
~MainWindow();

public slots:
void jump();
private:
Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H

and mainwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QxtApplication>
#include <QxtGlobalShortcut>
#include <QDebug>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow), m_action(new QxtGlobalShortcut(QKeySequence("Ctrl+Alt+A")))
{
ui->setupUi(this);
connect(m_action, SIGNAL(activated()), this, SLOT(jump()));
}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::jump()
{
qDebug() << "Jump!";
}



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..)

jpn
7th July 2009, 21:25
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.

Screeze
7th July 2009, 21:43
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?

Screeze
15th July 2009, 15:05
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!)

jpn
15th July 2009, 20:23
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. :)

Screeze
16th July 2009, 12:37
yes i did, but it didn't help

jpn
16th July 2009, 12:43
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.