Thank you again. Guess I can only hope that in future relases of Qt there will be a new function added that will allow it in easy way.![]()
Thank you again. Guess I can only hope that in future relases of Qt there will be a new function added that will allow it in easy way.![]()
If you mean hooks... well... I don't like it. I started creating in qt because I can't stand structure of WinApi...
I think about using QAbstractEventDispatcher in my program. If I get some free-time I'll look into doc and try to work with it.
I don't see how this would help. You want to intercept messages that are not meant for you, your application won't receive them unless you explicitly request that by installing a hook in Windows message loop.
QAbstractEventDispatcher Doc
An event dispatcher receives events from the window system and other sources. It then sends them to the QCoreApplication or QApplication instance for processing and delivery.That looks fine for me. If I understand correctly it can do the work that hooks do. Still, I have a problem with implementing it into my code... Guess, I have to try again...The event filter function set here is called for all messages taken from the system event loop before the event is dispatched to the respective target, including the messages not meant for Qt objects.
Last edited by rbrafi; 1st June 2011 at 23:39.
It doesn't say anything about events meant for other applications.
Ugh... You are right... I'm assuming that "messages not meant for Qt objects" are messages for other applications and I am probably wrong. Just in case I want to give it a try...
I have problem (again) with using Event Dispatcher.
My MainWindow constructor:
Qt Code:
ui->setupUi(this); eventDispatcher->setEventFilter(MyEventFilter);To copy to clipboard, switch view to plain text mode
Qt Code:
bool MainWindow::MyEventFilter(MSG *message) { switch(message->message) { case WM_KEYDOWN: qDebug("KEYDOWN"); switch(message->wParam) { case 0x41 : qDebug("- A"); break; case VK_F12 : qDebug("- F12"); break; default: break; } break; default: return false; } return false; }To copy to clipboard, switch view to plain text mode
Errorlog:
It runs, but crashes.Qt Code:
In constructor 'MainWindow::MainWindow(QWidget*): warning:'MyEventFilter' may be used uninitialized in this function warning:'MyEventFilter' may be used uninitialized in this functionTo copy to clipboard, switch view to plain text mode
How should I initialize MyEventFilter? I tried couple of times but effects were even worse than that...
QAbstractEventDispatcher::EventFilter is supposed to be a function and you are using it as a variable.
rbrafi (6th June 2011)
I decided that it is better to use RegisterHotKey() function from winApi. It saves a lot of time in my case. Still, I feel unsatisfied for some reasonThank you for your advices. They helped a lot.
Bookmarks