PDA

View Full Version : I think I found a bug about QTableWidget. Is this a bug?



John Smith
2nd March 2009, 12:22
I made a class which inherits QTableWidget and has resizeEvent().

#include <QDialog>
#include <QBoxLayout>
#include <QApplication>
#include <QBoxLayout>
#include <QTableWidget>
#include <QHeaderView>
#include <QResizeEvent>
#include <QDebug>

class TableBase : public QTableWidget
{
public:
TableBase(QWidget *parent = 0) : QTableWidget(10, 10, parent) {}
protected:
void resizeEvent(QResizeEvent *event) {/*...*/}
};

class A : public QDialog
{
public:
A();
private:
TableBase *table;
QVBoxLayout *layout;
};

A::A()
{
table = new TableBase(this);
layout = new QVBoxLayout(this);
layout->addWidget(table);
table->setSpan(0,0,5,1);
}

int main(int argc, char *argv[])
{
QApplication app(argc, argv);
A a;
a.show();
return app.exec();
}

When I executed the program, some of rows and columns were hidden because of small dialog box. So I resized the window, but I found following problems.
First, the horizontal header and the vertical header weren't redrawn.
Second, the program crashed with following assertion failure.
ASSERT: "i >= 0 && i < size()" in file ../../include/QtCore/../../src/corelib/tools/qbitarray.h, line 118

When I resized the window slightly and then resized one section, the headers were redrawn. Doing it repeatedly was not cause the program to crash.

Qt version is 4.5-rc1

spirit
2nd March 2009, 12:27
did you implement void resizeEvent(QResizeEvent *event) {/*...*/}?

John Smith
2nd March 2009, 12:33
Yes.
It resizes rows and columns size based on the widget size.
But the program crash regardless of function's implementation.

spirit
2nd March 2009, 12:34
comment you code and insert this one void resizeEvent(QResizeEvent *event) { QTableWidget::resizeEvent(event); } and tell if crash still appears.

John Smith
2nd March 2009, 12:38
Now it works properly.
Thanks very much.:)

spirit
2nd March 2009, 12:39
so, this means that a bug in your code. ;)