c++qtqt4.8qt5.7qkeysequence

Qt C++ Error no matching function for call to 'QString::QString(KeySequence)'


I used Qt 4.8.4 for my GUI-Project written in C++. Now I merged to Qt Version 5.7. After a long process of adapting my code I finally got my GUI to open. But when I run my calculation-code I still get this Error:

no matching function for call to 'QString::QString(KeySequence)'

in these lines:

  action = popup->addAction(EnhTableWidget::tr("&Copy") + QLatin1Char('\t') + QString(QKeySequence(QKeySequence::Copy)));
  ...
  action = popup->addAction(EnhTableWidget::tr("Delete") + QLatin1Char('\t') + QString(QKeySequence(QKeySequence::Delete)));
  ...
  action = popup->addAction(EnhTableWidget::tr("Select All") + QLatin1Char('\t') + QString(QKeySequence(QKeySequence::SelectAll)));

It seems that the use of QKeySequence is wrong. From the Qt-site I cannot see the problem.

What is wrong?

This is (part of) my code:

 #include "EnhTableWidget.h"
 #include <QKeyEvent>
 #include <QApplication>
 #include <QClipboard>
 #include <QHeaderView>
 #include <QKeySequence>
 #include <QAction>

 EnhTableWidget::EnhTableWidget(QWidget *parent) :
  QTableWidget(parent)
 {}


 void EnhTableWidget::keyPressEvent(QKeyEvent *event)
 {
       if ( event->matches(QKeySequence::Copy) )
        copy();
       else if ( event->matches(QKeySequence::Delete) || event->key() == Qt::Key_Backspace )
        deleteSelected();
       else if ( event->matches(QKeySequence::SelectAll) )
        selectAll();
       else
        QTableWidget::keyPressEvent(event);
 }


QMenu *EnhTableWidget::createStandardContextMenu()
  {
    QMenu *popup = new QMenu(this);
    popup->setObjectName(QLatin1String("qt_edit_menu"));
    QAction *action = 0;

  #ifndef QT_NO_CLIPBOARD

    action = popup->addAction(EnhTableWidget::tr("&Copy") + QLatin1Char('\t') + QString(QKeySequence(QKeySequence::Copy)));
    action->setEnabled(!selectionModel()->selectedIndexes().isEmpty());
    connect(action, SIGNAL(triggered()), SLOT(copy()));

  #endif

    action = popup->addAction(EnhTableWidget::tr("Delete") + QLatin1Char('\t') + QString(QKeySequence(QKeySequence::Delete)));
    action->setEnabled(isEnabled() && !selectionModel()->selectedIndexes().isEmpty());
    connect(action, SIGNAL(triggered()), this, SLOT(deleteSelected()));

        if (!popup->isEmpty())
              popup->addSeparator();

    action = popup->addAction(EnhTableWidget::tr("Select All") + QLatin1Char('\t') + QString(QKeySequence(QKeySequence::SelectAll)));
    action->setEnabled(isEnabled());
    connect(action, SIGNAL(triggered()), SLOT(selectAll()));

  return popup;
 }

Solution

  • QString doesn't have a constructor that takes a QKeySequence as an argument. You have to use QKeySequence::toString.

    action = popup->addAction(tr("&Copy") + QLatin1Char('\t') + QKeySequence(QKeySequence::Copy).toString());