radory
21st July 2010, 03:47
Hi all,
i'm new to QT, I get application crashed when i delete the last item in QListWidget....
following is my code...
#include <QtGui>
class MainWindow : public QWidget
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0)
: QWidget(parent)
{
_listWidget = new QListWidget(this);
_listWidget->resize(300,200);
_textEdit = new QTextEdit(this);
_textEdit->move(0,240);
for(int i= 0 ; i < 3 ; i++){
QListWidgetItem *item = new QListWidgetItem(_listWidget);
item->setData(Qt::DisplayRole, tr("item %1").arg(i));
item->setData(Qt::DecorationRole, qApp->style()->standardIcon(QStyle::SP_DirIcon));
}
connect(_listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWi dgetItem*)),
this, SLOT(listItemChged(QListWidgetItem*,QListWidgetIte m*)));
QPushButton *delBtn = new QPushButton(tr("Delete current item"), this);
delBtn->move(0, 210);
connect(delBtn, SIGNAL(clicked()), this, SLOT(delCurrItem()));
resize(600,700);
}
private slots:
void listItemChged(QListWidgetItem* currItem, QListWidgetItem*)
{
_textEdit->append(currItem->data(Qt::DisplayRole).toString());
}
void delCurrItem()
{
if(_listWidget->count() < 1) return;
delete _listWidget->currentItem();
}
private:
QListWidget *_listWidget;
QTextEdit *_textEdit;
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWin;
mainWin.show();
return app.exec();
}
Could somebody help me? thanks in advance....
Sorry for my poor English....
i'm new to QT, I get application crashed when i delete the last item in QListWidget....
following is my code...
#include <QtGui>
class MainWindow : public QWidget
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0)
: QWidget(parent)
{
_listWidget = new QListWidget(this);
_listWidget->resize(300,200);
_textEdit = new QTextEdit(this);
_textEdit->move(0,240);
for(int i= 0 ; i < 3 ; i++){
QListWidgetItem *item = new QListWidgetItem(_listWidget);
item->setData(Qt::DisplayRole, tr("item %1").arg(i));
item->setData(Qt::DecorationRole, qApp->style()->standardIcon(QStyle::SP_DirIcon));
}
connect(_listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWi dgetItem*)),
this, SLOT(listItemChged(QListWidgetItem*,QListWidgetIte m*)));
QPushButton *delBtn = new QPushButton(tr("Delete current item"), this);
delBtn->move(0, 210);
connect(delBtn, SIGNAL(clicked()), this, SLOT(delCurrItem()));
resize(600,700);
}
private slots:
void listItemChged(QListWidgetItem* currItem, QListWidgetItem*)
{
_textEdit->append(currItem->data(Qt::DisplayRole).toString());
}
void delCurrItem()
{
if(_listWidget->count() < 1) return;
delete _listWidget->currentItem();
}
private:
QListWidget *_listWidget;
QTextEdit *_textEdit;
};
#include "main.moc"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow mainWin;
mainWin.show();
return app.exec();
}
Could somebody help me? thanks in advance....
Sorry for my poor English....