我有一个QML应用程序(通过属性,Q_invokable
等)链接到C++代码中。 我可以使用QMLScene
在没有大部分C++框架的情况下启动QML应用程序,并且没有明显的问题(除了缺少应该从C++端提供的数据和功能之外)。
但是,当我构建和部署代码时,在QQMLApplicationEngine::Load()
调用期间,我在Qt框架内部获得了一个segfault。
我已经创建了一个简化的“虚拟”应用程序,似乎触发了完全相同的问题。
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
,我仍然会得到一个segfault,只是没有得到堆栈跟踪。 因此,如果注释掉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:用一个完整的非专有示例替换了前面的示例,该示例由从专有代码中精心选择的片段组成,该示例显示了相同的问题(并且具有稍短的stacktrace)。
平台信息:Qt 5.5.1运行在64位Debian 8上; 我的应用程序是用GCC5.1编译的,但是我在4.9.2和Clang3.7.0的预发布版本中看到了同样的错误,该版本现在已经有6个月了。 我还尝试使用QT5.4.0(它需要导入QTQuick2.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]
给你。 您需要引入Qt小部件依赖关系:
注意:由于Qt Creator 3.0,使用基于Qt Quick 2模板的Qt Quick Application wizard创建的项目默认使用QGuiApplication。 由于Qt Charts使用Qt Graphics View Framework进行绘图,因此必须使用QApplication。 在QGuiApplication替换为QApplication之后,使用向导创建的项目可以与Qt图表一起使用。
来自http://doc.qt.io/qtcharts/qtcharts-qmlmodule.html
这与我的猜测一致,即问题出在应用程序主题上,当您只使用QML应用程序(QGuiApplication)与更多的本机QtWidgets应用程序(QApplication)时,应用程序主题非常不同。