Simple QML QtCharts is crashing with SegFault
-
Hello everybody,
I don't know if I missing something trivial but what I did was:- Opening a new qml desktop project in qt 6.10.1
- Add an example ChartView element in Main.qml
- Add the required elements in CMakeLists.txt
I am on linux.
It builds fine but when I try to run the app I get a:
The command "<path>/appSSTV" terminated abnormally.And If I run the debugger this is the stack trace:
1 QWidgetTextControl::setCursorWidth qwidgettextcontrol.cpp 2493 0x7ffff77f9367 2 QWidgetTextControlPrivate::init qwidgettextcontrol.cpp 406 0x7ffff77f962f 3 QWidgetTextControl::QWidgetTextControl qwidgettextcontrol.cpp 868 0x7ffff77f962f 4 QGraphicsTextItemPrivate::textControl qgraphicsitem.cpp 10318 0x7ffff7967ce4 5 QGraphicsTextItem::document qgraphicsitem.cpp 9979 0x7ffff7968201 6 ChartTitle::ChartTitle charttitle.cpp 16 0x7ffff7d03425 7 ChartPresenter::createTitleItem chartpresenter.cpp 244 0x7ffff7cf564f 8 ChartPresenter::createTitleItem chartpresenter.cpp 241 0x7ffff7cf564f 9 ChartPresenter::setTitleFont chartpresenter.cpp 341 0x7ffff7cf5a45 10 QChart::setTitleFont qchart.cpp 331 0x7ffff7d21071 11 ChartThemeManager::decorateChart chartthememanager.cpp 82 0x7ffff7cfafe5 12 ChartThemeManager::setTheme chartthememanager.cpp 61 0x7ffff7cfd4cf 13 QChart::setTheme qchart.cpp 360 0x7ffff7d21151 14 QChartPrivate::init qchart.cpp 876 0x7ffff7d22163 15 QChart::QChart qchart.cpp 226 0x7ffff7d22254 16 DeclarativeChart::initChart declarativechart.cpp 470 0x7fffe95b3586 17 DeclarativeChart::DeclarativeChart declarativechart.cpp 422 0x7fffe95b3aa9 18 QQmlPrivate::QQmlElement<DeclarativeChart>::QQmlElement qqmlprivate.h 100 0x7fffe95c4cef 19 QQmlPrivate::createInto<DeclarativeChart> qqmlprivate.h 175 0x7fffe95c4cef 20 QQmlType::create qqmltype.cpp 510 0x7ffff5c06876 21 QQmlType::create qqmltype.cpp 504 0x7ffff5c06876 22 QQmlType::createWithQQmlData qqmltype.cpp 525 0x7ffff5c06922 23 QQmlObjectCreator::createInstance qqmlobjectcreator.cpp 1342 0x7ffff5bb3a12 24 QQmlObjectCreator::setPropertyBinding qendian.h 258 0x7ffff5bb55e5 25 QQmlObjectCreator::setupBindings qqmlobjectcreator.cpp 825 0x7ffff5bb7bb6 26 QQmlObjectCreator::populateInstance qqmlobjectcreator.cpp 1831 0x7ffff5bb996a 27 QQmlObjectCreator::createInstance qqmlobjectcreator.cpp 1492 0x7ffff5bb2fef 28 QQmlObjectCreator::create qqmlobjectcreator.cpp 199 0x7ffff5bbb7e1 29 QQmlComponentPrivate::beginCreate qqmlcomponent.cpp 1137 0x7ffff5b32a6d 30 QQmlComponent::beginCreate qqmlcomponent.cpp 1054 0x7ffff5b3310d 31 QQmlComponentPrivate::createWithProperties qqmlcomponent.cpp 977 0x7ffff5b342b2 32 QQmlComponent::create qqmlcomponent.cpp 938 0x7ffff5b3463d 33 QQmlApplicationEnginePrivate::finishLoad qqmlapplicationengine.cpp 158 0x7ffff5b0cc93 34 QQmlApplicationEnginePrivate::ensureLoadingFinishes qqmlapplicationengine.cpp 185 0x7ffff5b0ce9c 35 QQmlApplicationEnginePrivate::startLoad qqmlapplicationengine.cpp 144 0x7ffff5b0d236 36 main main.cpp 15 0x55555555784aThat at the end points in setCursorWidth to:
void QWidgetTextControl::setCursorWidth(int width) { Q_D(QWidgetTextControl); if (width == -1) width = QApplication::style()->pixelMetric(QStyle::PM_TextCursorWidth, nullptr, qobject_cast<QWidget *>(parent())); ^^^^^^ QApplication::style() is nullptr d->doc->documentLayout()->setProperty("cursorWidth", width); d->repaintCursor(); }These are the relevant files:
CMakeLists.txt:cmake_minimum_required(VERSION 3.16) project(SSTV VERSION 0.1 LANGUAGES CXX) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(Qt6 REQUIRED COMPONENTS Charts Core Gui Qml Quick Graphs) find_package(Qt6 REQUIRED COMPONENTS QuickControls2) qt_standard_project_setup(REQUIRES 6.8) qt_add_executable(appSSTV main.cpp ) qt_add_qml_module(appSSTV URI SSTV QML_FILES Main.qml ) # Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1. # If you are developing for iOS or macOS you should consider setting an # explicit, fixed bundle identifier manually though. set_target_properties(appSSTV PROPERTIES # MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appSSTV MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION} MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR} MACOSX_BUNDLE TRUE WIN32_EXECUTABLE TRUE ) target_link_libraries(appSSTV PRIVATE Qt::Charts Qt::Core Qt::Gui Qt::Qml Qt::Quick Qt6::QuickControls2 ) include(GNUInstallDirs) install(TARGETS appSSTV BUNDLE DESTINATION . LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} )main.cpp not changed from the template:
#include <QGuiApplication> #include <QQmlApplicationEngine> int main(int argc, char *argv[]) { QGuiApplication app(argc, argv); QQmlApplicationEngine engine; QObject::connect( &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); }, Qt::QueuedConnection); engine.loadFromModule("SSTV", "Main"); return app.exec(); }And main.qml:
import QtQuick import QtQuick.Controls.Universal import QtCharts ApplicationWindow { width: 640 height: 480 visible: true title: qsTr("Hello World") Universal.theme: Universal.Dark Universal.accent: Universal.Crimson ChartView { title: "Line Chart" anchors.fill: parent antialiasing: true LineSeries { name: "Line" XYPoint { x: 0; y: 0 } XYPoint { x: 1.1; y: 2.1 } XYPoint { x: 1.9; y: 3.3 } XYPoint { x: 2.1; y: 2.1 } XYPoint { x: 2.9; y: 4.9 } XYPoint { x: 3.4; y: 3.0 } XYPoint { x: 4.1; y: 3.3 } } } } -
T Tonelllo deleted this topic
-
T Tonelllo restored this topic
-
QChart needs a QApplication as it derives from QGraphicsWidget which is a QWidget: https://doc.qt.io/qt-6/qchart-qtcharts.html
-
QChart needs a QApplication as it derives from QGraphicsWidget which is a QWidget: https://doc.qt.io/qt-6/qchart-qtcharts.html
@Christian-Ehrlicher
Tank you very much for your reply. This was indeed the problem -
T Tonelllo has marked this topic as solved