加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – Q3ListView无法从Qt后备存储中取消注册或代码错误吗?

发布时间:2020-12-16 06:49:50 所属栏目:百科 来源:网络整理
导读:我有以下用例(实际上没有意义,因为它是从现实生活中的工作示例中最小化的,但我认为它在技术上仍然是正确的): class Dialog : public QDialog{public: Dialog(QWidget* parent) : QDialog(parent) { new Q3ListView(this); // this will crash// new QWidget
我有以下用例(实际上没有意义,因为它是从现实生活中的工作示例中最小化的,但我认为它在技术上仍然是正确的):

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实例似乎存在问题,这里是堆栈跟踪:

QtGuid4.dll!QWidgetBackingStore::staticContents(QWidget * parent,const QRect & withinClipRect) Line 499 C++

QtGuid4.dll!QWidgetBackingStore::sync() Line 1200 C++

QtGuid4.dll!QWidgetPrivate::syncBackingStore() Line 1896 C++

QtGuid4.dll!QWidget::event(QEvent * event) Line 8694 C++

QtGuid4.dll!QMainWindow::event(QEvent * event) Line 1479 C++

QtGuid4.dll!QApplicationPrivate::notify_helper(QObject * receiver,QEvent * e) Line 4565 C++

QtGuid4.dll!QApplication::notify(QObject * receiver,QEvent * e) Line 4530 C++

QtCored4.dll!QCoreApplication::notifyInternal(QObject * receiver,QEvent * event) Line 955 C++

QtCored4.dll!QCoreApplication::sendEvent(QObject * receiver,QEvent * event) Line 231 C++

QtCored4.dll!QCoreApplicationPrivate::sendPostedEvents(QObject * receiver,int event_type,QThreadData * data) Line 1579 C++

QtCored4.dll!qt_internal_proc(HWND__ * hwnd,unsigned int message,unsigned __int64 wp,__int64 lp) Line 498 C++

[External Code]

QtCored4.dll!QEventDispatcherWin32::processEvents(QFlags flags) Line 823 C++

QtGuid4.dll!QGuiEventDispatcherWin32::processEvents(QFlags flags) Line 1216 C++

QtCored4.dll!QEventLoop::processEvents(QFlags flags) Line 150 C++

QtCored4.dll!QEventLoop::exec(QFlags flags) Line 204 C++

QtCored4.dll!QCoreApplication::exec() Line 1227 C++

QtGuid4.dll!QApplication::exec() Line 3824 C++

qt_bug.exe!main(int argc,char * * argv) Line 60 C++

而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指向标有注释的行上的已删除对象).

免责声明:
我知道存在更优雅的解决方案,但这是遗留代码,并且根据Qt’s manual:

You can also delete child objects yourself,and they will remove themselves from their parents.

此代码有效.

我们在Windows 7(MSVC 2010 SP1,CL 16),Windows 8(MSVC 2013 U4,CL 18)和Fedora 20(GCC 4.8.3)上重现了这个问题.

解决方法

我已经提交了 bug report.由于它涉及图书馆的旧版本,因此无法修复它.

我们还是先后删除了Qt3Support,所以大家都建议;)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读