我使用Qt 4.8.4作为用C ++编写的GUI-Project。现在我合并到Qt版本5.7。经过长时间调整我的代码后,我终于打开了我的GUI。但是当我运行我的计算代码时,我仍然会收到此错误:
没有匹配函数来调用'QString :: QString(KeySequence)'
在这些方面:
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)));
它表明使用QKeySequence是错误的。从Qt网站我看不到问题。
有人知道出了什么问题吗?
谢谢!
这是我的代码的一部分:
#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;
}
答案 0 :(得分:2)
QString
没有一个以QKeySequence
为参数的构造函数。您必须使用QKeySequence::toString
。
action = popup->addAction(tr("&Copy") + QLatin1Char('\t') + QKeySequence(QKeySequence::Copy).toString());