I have a QML app with linkage (via properties, Q_INVOKABLE
, etc) into C++ code. I can launch the QML app without most of the C++ framework using qmlscene
, and there are no obvious problems (other than the missing data and functionality that's supposed to be provided from the C++ side).
However, when I build and deploy the code, I get a segfault inside the Qt framework during theQQmlApplicationEngine::load()
call.
I've created a simplified "dummy" app that appears to trigger the exact same issue.
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;
}
Note that without the SigCather
, I still get a segfault, I just don't get a stack-trace. This example is therefore reproducible if you comment out the SigCatcher
import and declaration.
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
}
}
There's almost nothing here, which leads me to believe that the ChartView
type itself might have a bug.
What might be going on? I don't even really know how to debug this; as far as I know, there's not even a way to use console.log
during engine::load()
before calling QGuiApplication::exec()
.
EDIT: Clarified that the app works correctly with qmlscene
(which I didn't know about when I first wrote the question).
EDIT 2: Replaced previous example, which was composed of carefully selected snippets taken from proprietary code, with a complete non-proprietary example that shows the same issue (and has a slightly shorter stacktrace).
Platform info: Qt 5.5.1 running on 64-bit Debian 8; my app is compiled with GCC 5.1, but I see the same error with 4.9.2 and a pre-release version of Clang 3.7.0 that's now about 6 months old. I've also tried using Qt 5.4.0 (which requires importing QtQuick 2.4
instead of 2.5
).
Stacktrace:
../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]
Here you go. You need to pull in the Qt Widgets dependency:
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.
from http://doc.qt.io/QtCharts/qtcharts-qmlmodule.html
This aligns with my guess that the issue is in the application theme, which is very different when you use QML only applications (QGuiApplication) in contrast to more native QtWidgets applications (QApplication).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With