Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No member named 'setResizeMode' in 'QHeaderView' - Convert Qt 4.7 to Qt 5.8

Tags:

c++

qt

qt5

I need to convert Qt legacy code from 4.7 to 5.8, I have a compilation error in Qt Creator 4.2.1 Clang 7.0(Apple) 64bit.

Looking in .cpp file

#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);
}

2 Errors in .cpp

In file included from ../src/ui/frmMainTableView_UI.cpp:1: ../src/ui/frmMainTableView_UI.h:21:18: warning : 'frmMainTableView_UI::setupUI' hides overloaded virtual function [-Woverloaded-virtual] virtual void setupUI(const QMap &columnNames_, bool hasRowLabels_, QWidget *parent_ = 0); ^

../src/ui/frmMainToolbar_UI.h:31:18: note: hidden overloaded virtual function 'frmMainToolbar_UI::setupUI' declared here: different number of parameters (2 vs 3) virtual void setupUI(const QMap &columnNames_, QWidget *parent_ = 0); ^

../src/ui/frmMainTableView_UI.cpp:24:30: error: no member named 'setResizeMode' in 'QHeaderView' ; did you mean 'sectionResizeMode'? table->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents); // JDL Error convert Qt4 to Qt5 ?? ^~~~~~~~~~~~~ sectionResizeMode /Users/john/Qt/5.8/clang_64/lib/QtWidgets.framework/Headers/qheaderview.h:133:16: note: 'sectionResizeMode' declared here ResizeMode sectionResizeMode(int logicalIndex) const; ^

../src/ui/frmMainTableView_UI.cpp:25:32: error: no member named 'setResizeMode' in 'QHeaderView' ; did you mean 'sectionResizeMode'? table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); // JDL Error convert Qt4 to Qt5 ?? ^~~~~~~~~~~~~ sectionResizeMode /Users/john/Qt/5.8/clang_64/lib/QtWidgets.framework/Headers/qheaderview.h:133:16: note: 'sectionResizeMode' declared here ResizeMode sectionResizeMode(int logicalIndex) const; ^

1 warning and 2 errors generated make: *** [frmMainTableView_UI.o] Error 1 18:29:48: The process "/usr/bin/make" exited with code 2. Error while building/deploying project mypersonalindex (kit: Desktop Qt 5.8.0 clang 64bit) When executing step "Make"

The Qt5 Docs mentioned Obsolete Members for QHeaderView The following members of class QHeaderView are obsolete. They are provided to keep old source code working. We strongly advise against using them in new code.

(obsolete) void setResizeMode(ResizeMode mode)

My C++ skill is pretty limited, do you see any minor tweaks that could convert this from Qt4 to Qt5. ... so what is the replacement?

like image 268
bullflag Avatar asked Mar 12 '17 02:03

bullflag


1 Answers

I guess you need to replace two obsolete lines:

table->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);  
table->horizontalHeader()->setResizeMode(QHeaderView::ResizeToContents); 

with the following Qt 5 code:

table->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); 
table->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); 

See the docs.

like image 142
demonplus Avatar answered Sep 22 '22 02:09

demonplus