PDA

View Full Version : Issues with QKeySequence when porting to Qt5



fedcer
3rd April 2013, 16:05
Hi, I have an application that works with Qt4 and uses the colon (":") as a shortcut for a QAction. I was testing out how the application worked under Qt5 and have found out that this particular shortcut does not work anymore. This isn't an issue specific to my application but with Qt5 in general, as it can be shown with the minimally reproducing application that I attach at the end of the message.

I have checked the docs but haven't found anything that has changed to guarantee this difference. Any idea on what it may be ? Or should I report this as a bug ?

Thanks,



#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

class MainWindow : public QMainWindow
{
Q_OBJECT

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

public slots:
void performTestAction();

private:
QAction *testAction;
};

#endif // MAINWINDOW_H




#include "mainwindow.h"

#include <QMainWindow>
#include <QAction>
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
testAction = new QAction("Test action", this);
// Neither of this work in Qt5 but do work in Qt4
testAction->setShortcut(QKeySequence(tr(":")));
//testAction->setShortcut(QKeySequence(Qt::Key_Colon));
connect(testAction, SIGNAL(triggered()), this, SLOT(performTestAction()));
addAction(testAction);
}

MainWindow::~MainWindow()
{ }

void MainWindow::performTestAction()
{
QMessageBox messageBox;
messageBox.setText("The action has been executed.");
messageBox.exec();
}




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

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow w;
w.show();

return a.exec();
}




#-------------------------------------------------
#
# Project created by QtCreator 2013-04-03T10:23:58
#
#-------------------------------------------------

QT += core gui

greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

TARGET = colontest
TEMPLATE = app


SOURCES += main.cpp\
mainwindow.cpp

HEADERS += mainwindow.h