【问题标题】:Segmentation fault in Qt Designer 4.6 with custom widget带有自定义小部件的 Qt Designer 4.6 中的分段错误
【发布时间】:2011-01-06 10:42:36
【问题描述】:

在 Qt Designer 4.6 中使用我的新 Qt Widget 时出现分段错误。尝试预览新小部件时会出现问题。

使用gdb时发现问题出在qdesigner_internal::WidgetFactory::applyStyleToTopLevel:

程序收到信号 SIGSEGV,分段错误。 qdesigner_internal::WidgetFactory::applyStyleToTopLevel (style=0x0, widget=0x1829df0) 在/var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/widgetfactory.cpp:777 777 /var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/widgetfactory.cpp:没有这样的文件或目录。 在 /var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/widgetfactory.cpp (gdb) BT #0 qdesigner_internal::WidgetFactory::applyStyleToTopLevel (style=0x0, widget=0x1829df0) at /var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/widgetfactory.cpp:777 #1 0x00007ffff7475bed in qdesigner_internal::QDesignerFormBuilder::createPreview (fw=, styleName=..., appStyleSheet=..., deviceProfile=, scriptErrors= 0x7fffffffbee0, errorMessage=0x7fffffffc3f0) 在/var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp:404 #2 0x00007ffff7476773 in qdesigner_internal::QDesignerFormBuilder::createPreview (fw=0x0, styleName=..., appStyleSheet=..., deviceProfile=..., errorMessage=0x0) 在/var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/qdesigner_formbuilder.cpp:439 #3 0x00007ffff7532b27 in qdesigner_internal::PreviewManager::createPreview (this=0x837f20, fw=0x1879200, pc=..., deviceProfileIndex=-1, errorMessage=0x7fffffffc3f0, initialZoom=-1) 在/var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/previewmanager.cpp:686 #4 0x00007ffff75343cf in qdesigner_internal::PreviewManager::showPreview (this=0x837f20, fw=0x1879200, pc=..., deviceProfileIndex=-1, errorMessage=0x7fffffffc3f0) 在/var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/previewmanager.cpp:760 #5 0x00007ffff753472f in qdesigner_internal::PreviewManager::showPreview (this=0x837f20, fw=0x1879200, style=..., deviceProfileIndex=-1, errorMessage=0x7fffffffc3f0) 在/var/tmp/qt-x11-src-4.6.0/tools/designer/src/lib/shared/previewmanager.cpp:659

因为那里传递了一个空指针:

void WidgetFactory::applyStyleToTopLevel(QStyle *style, QWidget *widget) { const QPalette standardPalette = style->standardPalette(); if (widget->style() == style && widget->palette() == standardPalette) return; //.... }

我是 Qt 新手,这是我的第一个自定义小部件。有没有人有解决这个问题的线索。

这是我的小部件代码

MBICInput::MBICInput(QWidget *parent) : QStackedWidget(parent){ displayPage = new QWidget(); displayPage->setObjectName(QString::fromUtf8("displayPage")); inputLB = new QLabel(displayPage); inputLB->setObjectName(QString::fromUtf8("inputLabel")); inputLB->setCursor(QCursor(Qt::PointingHandCursor)); addWidget(displayPage); EditPage = new QWidget(); EditPage->setProperty("EditInputLine", QVariant(true)); EditPage->setObjectName(QString::fromUtf8("EditPage")); inputInput = new QLineEdit(EditPage); inputInput->setGeometry(QRect(5, 10, 231, 25)); inputInput->setObjectName(QString::fromUtf8("input")); addWidget(EditPage); _animation = new QString(""); _message = new QString("Message"); _validator = new QRegExpValidator(QRegExp("[a-zA-Z]+"), this); } MBICInput::~MBICInput() { } QValidator::State MBICInput::validate(QString &text, int &pos) const{ return _validator->validate(text, pos); } void MBICInput::paintEvent(QPaintEvent *) { QPainter painter(this); painter.setRenderHint(QPainter::Antialiasing); } QSize MBICInput::minimumSizeHint() const{ return QSize(200, 40); } QSize MBICInput::sizeHint() const{ return QSize(200, 40); } void MBICInput::setAnimation(const QString &animation){ *_animation = animation; update(); } QString MBICInput::animation() const{ return *_animation; } void MBICInput::setMessage(const QString &message){ *_message = message; update(); } QString MBICInput::message() const{ return *_message; } void MBICInput::mousePressEvent(QMouseEvent *event){ if(currentIndex()==0){ setCurrentIndex(1); }else{ setCurrentIndex(0); } update(); }

【问题讨论】:

  • 预览小部件时,您使用的是哪种样式?您在什么操作系统上运行设计器?

标签: c++ qt qt4 segmentation-fault qt-designer


【解决方案1】:

applyStyleToTopLevel 函数中,您正在使用小部件指针,但未验证它是否为有效指针。因此,当使用 NULL 小部件指针执行 widget->style 时,它会崩溃。

【讨论】:

  • 是的,我知道,问题是函数 applyStyleToTopLevel 不是我的,它是 Qt Designer 源代码。我的问题是,我的代码中的什么触发了这样的错误??
【解决方案2】:

仅供参考,我刚刚在 Qt 版本 4.5.3-9 下编译了相同的代码,它在 4.5 设计器中工作得很好。可能是 Qt 4.6 的错误...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-07-02
    • 1970-01-01
    • 1970-01-01
    • 2019-02-07
    • 2015-04-13
    • 2014-06-24
    • 1970-01-01
    相关资源
    最近更新 更多