【发布时间】:2017-08-02 06:13:47
【问题描述】:
我需要将 Qt 遗留代码从 4.7 转换为 5.8,我在 Qt Creator 4.2.1 Clang 7.0(Apple) 64bit 中出现编译错误。
查看 .cpp 文件
#include "frmMainTableView_UI.h"
#include <QHeaderView>
void frmMainTableView_UI::setupUI(const QMap<int, QString> &columnNames_, bool hasRowLabels_, QWidget *parent_)
{
widget = new QWidget(parent_);
layout = new QVBoxLayout(widget);
layout->setSpacing(0);
layout->setMargin(1);
frmMainToolbar_UI::setupUI(columnNames_, widget);
tableSplitter = new QSplitter(widget);
table = new mpiTableView(hasRowLabels_, widget);
tableCopy = new QShortcut(Qt::CTRL + Qt::Key_C, table);
if (!hasRowLabels_)
table->verticalHeader()->hide();
table->setSelectionMode(QAbstractItemView::ExtendedSelection);
table->setSelectionBehavior(QAbstractItemView::SelectRows);
table->setAlternatingRowColors(true);
table->horizontalHeader()->setHighlightSections(false);
table->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); // Error convert Qt4 to Qt5 ??
table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); // Error convert Qt4 to Qt5 ??
tableSplitter->addWidget(table);
tableSplitter->setStretchFactor(0, 3);
layout->addWidget(toolbar);
layout->addWidget(tableSplitter);
}
.cpp 中的 2 个错误
在 ../src/ui/frmMainTableView_UI.cpp:1 中包含的文件中: ../src/ui/frmMainTableView_UI.h:21:18: 警告 : 'frmMainTableView_UI::setupUI' 隐藏重载的虚函数 [-Woverloaded-virtual] virtual void setupUI(const QMap &columnNames_, bool hasRowLabels_, QWidget *parent_ = 0); ^
../src/ui/frmMainToolbar_UI.h:31:18:注意:此处声明的隐藏重载虚函数“frmMainToolbar_UI::setupUI”:不同数量的参数(2 vs 3) virtual void setupUI(const QMap &columnNames_, QWidget *parent_ = 0); ^
../src/ui/frmMainTableView_UI.cpp:24:30: 错误:'QHeaderView'中没有名为'setResizeMode'的成员;你的意思是“sectionResizeMode”吗? 表->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); // JDL 错误将 Qt4 转换为 Qt5 ?? ^~~~~~~~~~~~~ sectionResizeMode /Users/john/Qt/5.8/clang_64/lib/QtWidgets.framework/Headers/qheaderview.h:133:16:注意:此处声明的“sectionResizeMode” ResizeMode sectionResizeMode(int logicalIndex) const; ^
../src/ui/frmMainTableView_UI.cpp:25:32: 错误:'QHeaderView'中没有名为'setResizeMode'的成员;你的意思是“sectionResizeMode”吗? table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); // JDL 错误将 Qt4 转换为 Qt5 ?? ^~~~~~~~~~~~~ sectionResizeMode /Users/john/Qt/5.8/clang_64/lib/QtWidgets.framework/Headers/qheaderview.h:133:16:注意:此处声明的“sectionResizeMode” ResizeMode sectionResizeMode(int logicalIndex) const; ^
生成 1 个警告和 2 个错误 make: *** [frmMainTableView_UI.o] 错误 1 18:29:48:进程“/usr/bin/make”以代码 2 退出。 构建/部署项目 mypersonalindex 时出错(套件:Desktop Qt 5.8.0 clang 64bit) 执行步骤“Make”时
Qt5 文档提到 QHeaderView 的过时成员 QHeaderView 类的以下成员已过时。提供它们是为了保持旧的源代码正常工作。我们强烈建议不要在新代码中使用它们。
(过时的)void setResizeMode(ResizeMode 模式)
我的 C++ 技能非常有限,您是否看到任何可以将其从 Qt4 转换为 Qt5 的小调整。 ...那么替换是什么?
【问题讨论】: