清除 QTreeWidget 时应用程序崩溃
我的应用程序在退出和清除 QTreeWidget 时因 BAD_ACCESS 崩溃。
这就是我填充树的第一层的方式:
std::set<UrlItem>::iterator i;
for(i = crawler->getUrls()->begin() ; i != crawler->getUrls()->end() ; i++) {
QList<QString> cells;
cells.append(i->url);
cells.append(i->httpStatusMessage);
cells.append(QString("%1").arg(i->statusCode));
QTreeWidgetItem *item = new QTreeWidgetItem(ui->resultTreeView, QStringList(cells));
ui->resultTreeView->addTopLevelItem(item);
}
我相信标题项导致了崩溃:
ui->resultTreeView->setHeaderItem(new QTreeWidgetItem(ui->resultTreeView, QStringList(headers)));
我在做什么导致这次崩溃?动态分配的项目将树小部件作为其父级,因此仅应在树小部件被销毁时才将其销毁。
My application is crashing with a BAD_ACCESS when quitting and when clearing the QTreeWidget.
This is how I'm populating the first level of the tree:
std::set<UrlItem>::iterator i;
for(i = crawler->getUrls()->begin() ; i != crawler->getUrls()->end() ; i++) {
QList<QString> cells;
cells.append(i->url);
cells.append(i->httpStatusMessage);
cells.append(QString("%1").arg(i->statusCode));
QTreeWidgetItem *item = new QTreeWidgetItem(ui->resultTreeView, QStringList(cells));
ui->resultTreeView->addTopLevelItem(item);
}
I believe that the header item is causing the crash:
ui->resultTreeView->setHeaderItem(new QTreeWidgetItem(ui->resultTreeView, QStringList(headers)));
What am I doing to cause this crash? The item that is dynamically allocated has the tree widget as it's parent so it should only be destroyed when the tree widget is.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看来我设置标题的方式错误。
这工作得很好:
现在,setHeaderItem 应该做什么以及为什么它使我的应用程序崩溃,我不知道,但上面的代码达到了预期的效果。
It seems I was setting the header the wrong way.
This works fine:
Now, what setHeaderItem was supposed to do and why it crashed my application I don't know but the code above achieved the desired effect.