Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. International
  3. German
  4. Programm Absturz bei Listview Model Delegate

Programm Absturz bei Listview Model Delegate

Scheduled Pinned Locked Moved Unsolved German
2 Posts 1 Posters 346 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • msauer751M Offline
    msauer751M Offline
    msauer751
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • msauer751M Offline
      msauer751M Offline
      msauer751
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved