-
Bug
-
Resolution: Done
-
P1: Critical
-
4.6.1
-
None
-
VS9, Windows XP
-
997490b36b28bca877409de97a506c969840bc43
Setup: Use a QListWidget to display a list of text items, and filter certain items out by using setHidden(true), for example by reading a filter string from a QLineEdit (see code below).
Normal behavior: Compile and run the example code, observe that entering something in the lineEdit causes non-matching items to disappear from the QListWidget.
Bug: With the lineEdit completely empty, scroll the QListWidget all the way to the bottom. Enter the digit "1" into the lineEdit. The application crashes with an "index out of range" assertion.
Note: The application also crashes when scrolling down close to the bottom, but not completely to the bottom.
This is an always reproducible bug in Qt 4.6.1 (4.5.3 works fine, 4.6.0 untested) with the following code:
===============mainwindow.h======================
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QtGui>
class QListWidget;
class QLineEdit;
class MainWindow : public QWidget
{
Q_OBJECT
public:
MainWindow();
~MainWindow();
private slots:
void searchChanged(const QString & text);
private:
QListWidget* mList;
QLineEdit* mLineedit;
};
#endif //MAINWINDOW_H
=============mainwindow.cpp==================
#include "mainwindow.h"
#include <QListWidget>
#include <QGridLayout>
#include <QLineEdit>
MainWindow::MainWindow()
{
QGridLayout* layout = new QGridLayout(this);
mList = new QListWidget(this);
mLineedit = new QLineEdit(this);
layout->addWidget(mLineedit);
layout->addWidget(mList);
for (int i = 1; i < 150; i++)
{ mList->addItem(QString("%1) some entry").arg(i)); } connect(mLineedit, SIGNAL(textChanged(const QString &)), this, SLOT(searchChanged(const QString &)));
}
void MainWindow::searchChanged(const QString & text)
{
for (int i = 0; i < mList->count(); i++)
{
if (QListWidgetItem *entry = mList->item)
}
}
MainWindow::~MainWindow()
{
}