【问题标题】:QtQuick ChartView QML object seg-faults causes QML-engine segfault during loadQtQuick ChartView QML object seg-faults 在加载期间导致 QML-engine segfault
【发布时间】:2016-03-10 00:41:51
【问题描述】:

我有一个 QML 应用程序(通过属性、Q_INVOKABLE 等)链接到 C++ 代码。我可以使用qmlscene 在没有大部分 C++ 框架的情况下启动 QML 应用程序,并且没有明显的问题(除了应该从 C++ 端提供的丢失的数据和功能)。

但是,当我构建和部署代码时,我在QQmlApplicationEngine::load() 调用期间在 Qt 框架内遇到了段错误。

我创建了一个简化的“虚拟”应用,似乎触发了完全相同的问题。

C++ 应用程序:

#include <QGuiApplication>
#include <QQmlApplicationEngine>

#include "SigCatcher.hpp"  // Proprietary code

int main(
    int argc,
    char *argv[])
{
  SigCatcher sig_catcher;  // Just catches signals & prints stacktrace

  QGuiApplication app(argc, argv);

  QQmlApplicationEngine engine;

  engine.load(
      QUrl(QStringLiteral("qrc:/main.qml")));

  return 0;
}

请注意,如果没有SigCather,我仍然会遇到段错误,只是没有得到堆栈跟踪。因此,如果您注释掉 SigCatcher 导入和声明,则此示例可以重现。

main.qml:

import QtQuick 2.5
import QtQuick.Controls 1.3
import QtCharts 2.0

ApplicationWindow {
    id:  winRoot
    visible: true

    width:  1024 - 24
    height:  768 - 80

    minimumWidth: width
    minimumHeight: height
    maximumHeight: minimumHeight
    maximumWidth: minimumWidth

    ChartView {
        id: sparkline
        anchors.top: parent.top
        anchors.right: parent.right
        anchors.left: parent.left
    }
}

这里几乎什么都没有,这让我相信ChartView 类型本身可能存在错误。

可能会发生什么?我什至不知道如何调试它;据我所知,在调用QGuiApplication::exec() 之前,甚至没有办法在engine::load() 期间使用console.log

编辑:澄清了该应用程序与qmlscene(我第一次写问题时不知道)正常工作。

编辑 2: 用一个完整的非专有示例替换了前面的示例,该示例由从专有代码中精心挑选的 sn-ps 组成(并且堆栈跟踪稍短一些) )。


平台信息: Qt 5.5.1 在 64 位 Debian 8 上运行;我的应用程序是使用 GCC 5.1 编译的,但我在 4.9.2 和现在大约 6 个月大的 Clang 3.7.0 预发布版本中看到了同样的错误。我也尝试过使用 Qt 5.4.0(需要导入 QtQuick 2.4 而不是 2.5)。

堆栈跟踪:

../obj/X64_ATOM/debug/GUI/AucLocalGui2(_ZN22TracePrinterImpl_Linux16Print_stackTraceEv+0x42)[0x401e54]
../obj/X64_ATOM/debug/GUI/AucLocalGui2(_ZN12TracePrinter16Print_stackTraceEv+0x9)[0x401e7d]
../obj/X64_ATOM/debug/GUI/AucLocalGui2(_ZN20SigCatcherImpl_Linux15OnCatch_signal_Ei+0x68)[0x4022c6]
/lib/x86_64-linux-gnu/libc.so.6(+0x35180)[0x7fe0a2234180]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Widgets.so.5(_ZN18QWidgetTextControl14setCursorWidthEi+0x55)[0x7fe0a527fb15]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Widgets.so.5(_ZN18QWidgetTextControlC1EP7QObject+0x5d)[0x7fe0a527fced]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Widgets.so.5(+0x443047)[0x7fe0a53a6047]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Widgets.so.5(_ZNK17QGraphicsTextItem8documentEv+0xd)[0x7fe0a53a633d]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x63821)[0x7fe098d74821]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x56cd3)[0x7fe098d67cd3]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x5727d)[0x7fe098d6827d]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x597d6)[0x7fe098d6a7d6]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x5bb7c)[0x7fe098d6cb7c]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/../../lib/libQt5Charts.so.2(+0x5fb8f)[0x7fe098d70b8f]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/libqtchartsqml2.so(+0x2f044)[0x7fe099072044]
/opt/Qt/5.5.1/5.5/gcc_64/qml/QtCharts/libqtchartsqml2.so(+0x16680)[0x7fe099059680]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZNK8QQmlType6createEv+0x3b)[0x7fe0a436e07b]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cf472)[0x7fe0a43cf472]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cc85d)[0x7fe0a43cc85d]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cd45e)[0x7fe0a43cd45e]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cde8e)[0x7fe0a43cde8e]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cea8b)[0x7fe0a43cea8b]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(+0x2cfcef)[0x7fe0a43cfcef]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN20QQmlComponentPrivate11beginCreateEP15QQmlContextData+0x145)[0x7fe0a43592e5]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN13QQmlComponent6createEP11QQmlContext+0x68)[0x7fe0a4359728]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN28QQmlApplicationEnginePrivate13_q_finishLoadEP7QObject+0x262)[0x7fe0a43c0de2]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN28QQmlApplicationEnginePrivate9startLoadERK4QUrlRK10QByteArrayb+0xd2)[0x7fe0a43c1082]
/opt/Qt/5.5.1/5.5/gcc_64/lib/libQt5Qml.so.5(_ZN21QQmlApplicationEngine4loadERK4QUrl+0x1d)[0x7fe0a43c10bd]
../obj/X64_ATOM/debug/GUI/AucLocalGui2(main+0x84)[0x401ae4]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf5)[0x7fe0a2220b45]
../obj/X64_ATOM/debug/GUI/AucLocalGui2[0x401959]

【问题讨论】:

  • 给定堆栈跟踪和代码 (code.qt.io/cgit/qt/qtbase.git/tree/src/widgets/widgets/…) 的高级猜测将是构造函数调用 init() 导致调用 setCursorWidth(-1) 然后导致 width = QApplication::style()-&gt;pixelMetric(QStyle::PM_TextCursorWidth); 或 @ 崩溃987654340@ – 例如当没有设置样式或布局时。你能添加加载所有这些 QML 的 main 函数吗?
  • 你的 QML 根元素是什么样子的?
  • @SimonWarta 你是说QQmlApplicationEngine::load()直接加载的顶级qml文件吗?我已将其缩减为一个简单的 ApplicationWindow,只包含一个 SparklineChart 元素,但如果您愿意,我可以发布它。
  • 我没有看到任何看起来应该设置负光标宽度的东西....
  • 检查在 QWidgetTextControl 的所有 3 个构造函数中调用的 init() 函数。它可能是内联的,因此您在调用堆栈中看不到它。 -1 必须是某种默认值。

标签: c++ qt segmentation-fault qml


【解决方案1】:

给你。您需要引入 Qt Widgets 依赖项:

注意:从 Qt Creator 3.0 开始,使用基于 Qt Quick 2 模板的 Qt Quick Application 向导创建的项目默认使用 QGuiApplication。由于 Qt Charts 使用 Qt Graphics View Framework 进行绘图,因此必须使用 QApplication。使用向导创建的项目在将 QGuiApplication 替换为 QApplication 后可与 Qt Charts 一起使用。

来自http://doc.qt.io/QtCharts/qtcharts-qmlmodule.html

这与我的猜测一致,即问题出在应用程序主题中,当您使用仅 QML 的应用程序 (QGuiApplication) 与更多本机 QtWidgets 应用程序 (QApplication) 相比时,这是非常不同的。

【讨论】:

  • 太棒了,切换到QApplication 已经解决了这个问题。谢谢你。虽然我很惊讶当 QGuiApplication 尝试import Qt Charts 时触发的不仅仅是一条错误消息。
  • QtChart 的工作是检测它运行在哪种应用程序上并打印错误信息。请随意将其作为 Qt 的错误提交:bugreports.qt.io
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-05
  • 1970-01-01
  • 1970-01-01
  • 2018-05-23
  • 1970-01-01
  • 2017-09-10
  • 1970-01-01
相关资源
最近更新 更多