c – Q3ListView无法从Qt后备存储中取消注册或代码错误吗?
我有以下用例(实际上没有意义,因为它是从现实生活中的工作示例中最小化的,但我认为它在技术上仍然是正确的):
class Dialog : public QDialog { public: Dialog(QWidget* parent) : QDialog(parent) { new Q3ListView(this); // this will crash // new QWidget(this); // this won't crash } }; 根据添加到Dialog的内容,删除Dialog实例时程序将崩溃(如代码段中的注释所示),但仅在主窗口的标志被修改时才会崩溃.以下是MainWindow类的代码,它使用Dialog: class MainWindow : public QMainWindow { public: // the fact that the widget (dialog) below // has no chance to show seems irrelevant. // In the real scenario I have,the widget is shown on // the screen and is closed by the user. // I've just put the whole sequence of pieces of code // that result from signal/slot calls,that in turn // result from a point&click scenario in our application // into the following function for brevity. void go() { auto dialog = new Dialog(this); dialog->show(); dialog->close(); disableAlwaysOnTop(); delete dialog; // or dialog->deleteLater(); } void disableAlwaysOnTop() { setAttribute(Qt::WA_Resized,true); Qt::WindowFlags flags = windowFlags(); setWindowFlags(flags ^ (Qt::CustomizeWindowHint | Qt::WindowStaysOnTopHint)); setVisible(true); } }; 和main的实现: int main(int argc,char** argv) { QApplication app(argc,argv); MainWindow mainWindow; mainWindow.show(); mainWindow.go(); return app.exec(); } 所有线条似乎都必须重现崩溃. 这是Qt中的错误,还是我做错了什么? 允许手动删除小部件的子节点,并且它们应该自动从父节点取消注册,如下面手册中的引用所示.在我的实际案例中,窗口小部件被删除以从GUI中消失,并且它适用于其他窗口小部件组合.如上面的评论所示,更改删除对话框;到dialog-> deleteLater();没有帮助. 从Qt的后备存储中删除Q3ListView实例似乎存在问题,这里是堆栈跟踪:
而Qt的代码试图在堆栈跟踪中指示的行中使用指向已删除对象的指针: for (int i = 0; i < count; ++i) { QWidget *w = staticWidgets.at(i); QWidgetPrivate *wd = w->d_func(); if (!wd->isOpaque || !wd->extra || wd->extra->staticContentsSize.isEmpty() // **** || !w->isVisible() || (parent && !parent->isAncestorOf(w))) { continue; } (wd指向标有注释的行上的已删除对象). 免责声明:
此代码有效. 我们在Windows 7(MSVC 2010 SP1,CL 16),Windows 8(MSVC 2013 U4,CL 18)和Fedora 20(GCC 4.8.3)上重现了这个问题. 解决方法
我已经提交了
bug report.由于它涉及图书馆的旧版本,因此无法修复它.
我们还是先后删除了Qt3Support,所以大家都建议;) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |