UGlobalHotkey icon indicating copy to clipboard operation
UGlobalHotkey copied to clipboard

Cannot define multiple actions for multiple hotkeys

Open akamensky opened this issue 5 years ago • 3 comments

This great add-on, exactly what I need, except for the fact that I don't seem to be able to define multiple hotkeys using below code:

    hotkeyOne = new UGlobalHotkeys();
    hotkeyOne->registerHotkey("Ctrl+Shift+B");
    connect(hotkeyOne, SIGNAL(activated(size_t)), this, SLOT(actionOne()));

    hotkeyTwo = new UGlobalHotkeys();
    hotkeyTwo->registerHotkey("Ctrl+Shift+L");
    connect(hotkeyTwo, SIGNAL(activated(size_t)), this, SLOT(actionTwo()));

Whenever I use try to define it like this both hotkeys get registered, BUT both of them trigger actionTwo only. actionOne never gets executed.

akamensky avatar Sep 09 '19 14:09 akamensky

Meantime this approach works, but it is not inline with Qt5 style:

    hotkeyOne = new UGlobalHotkeys();
    hotkeyOne->registerHotkey("Ctrl+Shift+B", 1);
    hotkeyOne->registerHotkey("Ctrl+Shift+L", 2);
    connect(hotkeyOne, &UGlobalHotkeys::activated, [=](size_t id){
        switch (id) {
        case 1:
            actionOne();
            break;
        case 2:
            actionTwo();
            break;
        }
    });

akamensky avatar Sep 09 '19 14:09 akamensky

Hello! I'm sorry, but I do not actively support this repo. The second approach is exactly what was intended upon creation of this add-on.

antvconst avatar Sep 09 '19 15:09 antvconst

Then I think it would be good to have an example of how to use it added to readme.

akamensky avatar Sep 12 '19 12:09 akamensky