程序启动时弹出窗口显示:
应用程序发生异常unknow software exception (0xc000001d),位置为0x004217aa。要终止程序,请按确定。
源代码如下;
//main.cpp
#include <QApplication>
#include "tree.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Tree *treeWidget = new Tree;
treeWidget->show();
return app.exec();
}
//tree.h
#ifndef TREE_H
#define TREE_H
#include <QWidget>
class QTreeWidget;
class QTreeWidgetItem;
class Tree : public QWidget
{
Q_OBJECT
public:
Tree(QWidget *parent = 0);
// virtual ~Tree();
// protected:
private slots:
void currentIndex(QTreeWidgetItem *current);
private:
void init();
QTreeWidget *tree;
};
#endif // TREE_H
//tree.cpp
#include <QTreeWidget>
#include <QTreeWidgetItem>
#include <QHBoxLayout>
#include <QMessageBox>
#include "tree.h"
Tree::Tree(QWidget *parent)
:QWidget(parent)
{
init();
}
void Tree::init()
{
tree = new QTreeWidget;
tree->setColumnCount(2);
tree->setHeaderLabels(QStringList()<<tr("first")<<tr("second"));
connect(tree,SIGNAL( itemClicked(QTreeWidgetItem * , int)),
this,SLOT(currentIndex(QTreeWidgetItem*)));
QTreeWidgetItem *caseInformation = new QTreeWidgetItem(tree);
caseInformation->setText(0,tr("caseInformation"));
caseInformation->setText(1,tr("caseInformation2"));
QTreeWidgetItem *general = new QTreeWidgetItem(caseInformation);
general->setText(0,tr("general"));
general->setText(1,tr("general2"));
QTreeWidgetItem *reportInformation = new QTreeWidgetItem(tree,caseInformation);
reportInformation->setText(0,tr("reportInformation"));
QTreeWidgetItem *general2 = new QTreeWidgetItem(reportInformation);
general2->setText(0,tr("general"));
general2->setText(1,tr("general2"));
QHBoxLayout *main = new QHBoxLayout;
main->addWidget(tree);
main->addStretch(1);
setLayout(main);
}
void Tree::currentIndex(QTreeWidgetItem *current)
{
QMessageBox::information(this,tr("information"),
QString::number(tree->indexOfTopLevelItem(current)));
}
文字[ 此贴被dara在2006-03-08 18:46重新编辑 ]