开发者

QxtGlobalShortcut causes SIGSEGV in console application

I am writing a console application that allows you to use ECMAScript to move the mouse about, and define hot keys etc. The mouse stuff works, and now I am trying to add in the ability to define hot keys that when pressed will call a QtScript handler function.

The problem is, when I try to use QxtGlobalShortcut to create the hot key, I get a SIGSEGV and everything crashes.

Here is the code:

int Keyboard::hot_key(QString key) {
    QxtGlobalShortcut shortcut;
    shortcut.setShortcut(QKeySequence(key));
    shortcut.setEnabled(true);
    connect(&shortcut, SIGNAL(activated()), this, SLOT(hot_key_pressed()));
    return 0;
}

This line QxtGlobalShortcut shortcut;, if I gut the entire function except for that line, it still throws a seg fault.

And the debugger says:

1   ZNK17QxtGlobalShortcut8shortcutEv   C:\Qxt\lib\QxtGui.dll   0   0x6f6f14a6  
2   ZN17QxtGlobalShortcutC1EP7QObject   C:\Qxt\lib\QxtGui.dll   0   0x6f6f14f7  
3   Keyboard::hot_key   keyboard.cpp    16  0x403c0c    
4   Keyboard::qt_metacall   moc_keyboard.cpp    74  0x404740    
5   QMetaObject::metacall   qmetaobject.cpp 237 0x8f5ff8

Considering how not so easy, in my opinion, Windows hotkeys are, I'd really like to use Qxt, but so far I am just hitting a wall. If anyone could point me in the right direction, or even recommend some o开发者_JS百科ther library that might be able to help me, or a tutorial on hotkeys that would be awesome.

Thanks in advance!


Your shortcut object is constructed on the stack. It will get deleted as soon you leave that function, so your code is bound to fail even if it did not die in that function.

You should be creating that object with:

 QxtGlobalShortcut *shortcut = new QxtGlobalShortcut;

If you care about not leaking that, store that pointer as a member of your class and delete it in it's destructor.

As for the crash, that could happen if you are using a version of Qxt older than 6.0 and haven't initialized a QxtApplication yet.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜