gpt4 book ai didi

c++ - Qt C++错误没有匹配函数调用 'QString::QString(KeySequence)'

转载 作者:行者123 更新时间:2023-11-30 03:31:04 25 4
gpt4 key购买 nike

我在用 C++ 编写的 GUI 项目中使用了 Qt 4.8.4。现在我合并到 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;
}

最佳答案

QString 没有将 QKeySequence 作为参数的构造函数。你必须使用 QKeySequence::toString .

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

关于c++ - Qt C++错误没有匹配函数调用 'QString::QString(KeySequence)',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44515215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com