1

I'm looking for a function that returns the width of a QTableWidget horizontal header: after a deep research in the official documentation, the only thing I've found is this, but the debugger send me this error at the line:

int section = table->horizontalHeader()->defaultSectionSize();

error: invalid use of incomplete type 'class QHeaderView'

Of course, I specified the ResizeMode in the constructor:

table->horizontalHeader()->setSectionResizeMode(QHeaderView::Interactive);
user3713179
  • 361
  • 3
  • 12

1 Answers1

1

Introduction

QTableView::horizontalHeader is declared to return a pointer to a QHeaderView, the problem is that the definition of what this pointer refers to isn't declared in <QTableWidget> (more specifically in <QTableView>, which QTableWidget includes); it's merely forward declared.

The compiler is telling you that you are trying to use an incomplete type, meaning that the compiler doesn't know the definition of said type.

Having a pointer to an incomplete type is fine, but you are not allowed (and cannot) to access anything inside it.


Solution

The full declaration of QHeaderView is available in <QHeaderView>, include it and the compiler will be satisfied.

#include <QHeaderView> // <- required
Community
  • 1
  • 1
Filip Roséen - refp
  • 62,493
  • 20
  • 150
  • 196