Programm Absturz bei Listview Model Delegate
-
Hallo,
ich habe in meinen Projekt ein QML UI, das eine Tabelle basierend auf einer C++ Klasse (QQmlListProperty)
Q_PROPERTY(QQmlListProperty<geo::GeoPoint> ui_items READ ui_items NOTIFY chgPointList)
darstellen soll.
Der Modelview Aufruf sieht so aus:
import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import GC 1.0 import assets 1.0 import components 1.0 Panel { property GeoController geoController width: parent.width*0.75 x: 15 contentComponent: Column { width: parent.width spacing: Style.sizeControlSpacing KoordFindListItemHeader { } ListView { id: itemsView anchors { top: parent.top left: parent.left right: parent.right leftMargin: Style.sizeScreenMargin rightMargin: Style.sizeScreenMargin bottomMargin: Style.sizeScreenMargin } clip: true model: geoController.ui_items delegate: KoordFindListItemDelegate { geoPoint: modelData } } } }
Das List Element ist hier definiert:
QQmlListProperty<GeoPoint> GeoController::ui_items(void) { Q_D(GeoController); return QQmlListProperty<GeoPoint>(this, PointList); }
#ifndef GEOPOINT_H #define GEOPOINT_H #include <QObject> #include <QScopedPointer> #include <QGeoCoordinate> #include "lib-geo_global.h" namespace geo { class GeoPointPrivate; class LIBGEO_EXPORT GeoPoint : public QObject { Q_OBJECT Q_PROPERTY(QString ui_Koord READ getKoord CONSTANT) Q_PROPERTY(QString ui_Dist READ getDistStr CONSTANT) Q_PROPERTY(QString ui_Azi READ getAziStr CONSTANT) Q_PROPERTY(qreal ui_Lat READ getLat CONSTANT) Q_PROPERTY(qreal ui_Lon READ getLon CONSTANT) public: GeoPoint(QObject *parent = nullptr); ~GeoPoint(); void setPoint(const QGeoCoordinate&); void setAzimut(const qreal&); void setDistance(const qreal&); void Clear(void); QGeoCoordinate getPoint(void); qreal getAzimut(void); qreal getDistance(void); const QString getKoord(void); const QString &getDistStr(void); const QString &getAziStr(void); const qreal &getLat(void); const qreal &getLon(void); protected: const QScopedPointer<GeoPointPrivate> d_ptr; private: Q_DISABLE_COPY(GeoPoint) Q_DECLARE_PRIVATE(GeoPoint) }; } #endif // GEOPOINT_H
Die Ausgabe übernimmt die Delegate UI:
import QtQuick 2.12 import QtQuick.Controls 2.12 import QtQuick.Layouts 1.12 import QtQuick.Window 2.12 import GC 1.0 import assets 1.0 import components 1.0 Item { property GeoPoint geoPoint implicitWidth: parent.width implicitHeight: background.height //x: 15 Component.onCompleted: { console.log('Point: ', geoPoint, ', Koord: ', geoPoint.ui_Koord); } Rectangle { id: background width: parent.width height: textKoord.implicitHeight color: Style.colourPanelBackground Text { Component.onCompleted: { console.log('Point: ', geoPoint, ', Koord: ', geoPoint.ui_Koord); } id:textKoord anchors { top: parent.top left: parent.left } //text: geoPoint.ui_Koord font { pixelSize: Style.pixelSizeDataControls family: Style.regular weight: Font.Normal } color: "#000000" width: 500 rightPadding: 2 leftPadding: 2 bottomPadding: 2 topPadding: 2 verticalAlignment: Qt.AlignVCenter horizontalAlignment: Qt.AlignHCenter } }
Die Console Log wird noch richtig ausgegeben
qml: Point: geo::GeoPoint(0x7ffc7d048960) , Koord: N 47° 54.401 E 12° 7.117
qrc:/components/KoordFindListItemDelegate.qml:32: TypeError: Cannot read property 'ui_Koord' of null
16:50:09: Das Programm ist abgestürzt.
16:50:09: Der Prozess wurde gestoppt.Und dann bekomme ich einen Segmentation Fault. Außerdem habe ich auch keine Ahnung wo der Type Error herkommt, obwohl die Ausgabe mittels Console.log funktioniert hat. Mittels Debugger konnte ich feststellen, dass in der Liste 2 Einträge existieren. Da ich an anderer Stelle eine Liste nach dem selben Prinzip anzeige, verstehe ich nicht so ganz, warum ich hier einen Seg. Fault bekomme.
Könnt Ihr mir hier weiterhelfen, wo der Fehler liegt?Danke Euch.
gruss
martin -
Also das mit dem Absturz habe ich jetzt hinbekommen. Das hatte etwas mit implicitHeigh / implicitWidth zu tun.
Was immer noch seltsam ist, das ist der Fehler
qrc:/components/KoordFindListItemDelegate.qml:32: TypeError: Cannot read property 'ui_Koord' of null
beim zuweisen von
text: geoPoint.ui_Koord
in der Delegate ui.
gruss
martin