但是,当我构建和部署代码时,在QQmlApplicationEngine :: load()调用期间,我在Qt框架内得到了一个段错误.
我创建了一个简化的“虚拟”应用程序,似乎触发了完全相同的问题.
C App:
#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类型本身可能有一个bug.
可能会发生什么?我甚至不知道如何调试这个;据我所知,在调用QGuiApplication :: exec()之前,甚至没有办法在engine :: load()期间使用console.log.
编辑:澄清该应用程序与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]
解决方法
Note: Since Qt Creator 3.0 the project created with Qt Quick Application wizard based on Qt Quick 2 template uses QGuiApplication by default. As Qt Charts utilizes Qt Graphics View Framework for drawing,QApplication must be used. The project created with the wizard is usable with Qt Charts after the QGuiApplication is replaced with QApplication.
从http://doc.qt.io/QtCharts/qtcharts-qmlmodule.html
这符合我的猜测,问题出现在应用程序主题中,当您使用仅QML应用程序(QGuiApplication)与更多本机QtWidgets应用程序(QApplication)相比时,这是非常不同的.