当前位置:  开发笔记 > 编程语言 > 正文

QtQuick ChartView QML对象seg-faults在加载期间导致QML引擎段错误

如何解决《QtQuickChartViewQML对象seg-faults在加载期间导致QML引擎段错误》经验,为你挑选了1个好方法。

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

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

我创建了一个简化的"虚拟"应用程序,似乎触发了完全相同的问题.

C++应用程序:

#include 
#include 

#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类型本身可能有一个bug.

可能会发生什么?我甚至不知道如何调试这个; 据我所知,还有的甚至没有使用方法console.logengine::load()调用之前QGuiApplication::exec().

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

编辑2:替换了前面的示例,该示例由从专有代码中精心挑选的片段组成,带有完整的非专有示例,显示相同的问题(并且具有稍短的堆栈跟踪).


平台信息: Qt 5.5.1在64位Debian 8上运行; 我的应用程序是用GCC 5.1编译的,但是我看到4.9.2的同一错误和Clang 3.7.0的预发布版本现在大约6个月了.我也尝试过使用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]

Simon Warta.. 16

干得好.你需要引入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)相比时,这是非常不同的.



1> Simon Warta..:

干得好.你需要引入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尝试导入Qt图表时,并不仅触发了一条错误消息。
推荐阅读
135369一生真爱_890
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有