Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Crash with Qt6.11.1 and VerticalHeaderView
Qt 6.11 is out! See what's new in the release blog

Crash with Qt6.11.1 and VerticalHeaderView

Scheduled Pinned Locked Moved Unsolved General and Desktop
10 Posts 3 Posters 570 Views 2 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.
  • DuBuD Offline
    DuBuD Offline
    DuBu
    wrote on last edited by
    #1

    Hi,

    I've got the following example code:
    main.cpp:

    #include "tablemodel.h"
    #include <QGuiApplication>
    #include <QQmlApplicationEngine>
    
    int main(int argc, char *argv[]) {
      QGuiApplication app(argc, argv);
    
      qmlRegisterType<TableModel>("Models", 1, 0, "TableModel");
    
      QQmlApplicationEngine engine;
      QObject::connect(
          &engine, &QQmlApplicationEngine::objectCreationFailed, &app, []() { QCoreApplication::exit(-1); },
          Qt::QueuedConnection);
      engine.loadFromModule("MatrixView", "Main");
    
      return QGuiApplication::exec();
    }
    

    tablemodel.h:

    #pragma once
    
    #include <QAbstractTableModel>
    
    class TableModel : public QAbstractTableModel {
    public:
      enum RoleNames { NameRole = Qt::UserRole };
      explicit TableModel(QObject *parent = nullptr) : QAbstractTableModel{parent} {}
    
      // QAbstractItemModel interface
    public:
      int rowCount(const QModelIndex &parent) const override { return 2; }
      int columnCount(const QModelIndex &parent) const override { return 2; }
      QVariant data(const QModelIndex &index, int role) const override { return ""; }
      QVariant headerData(int section, Qt::Orientation orientation, int role) const override { return ""; }
      QHash<int, QByteArray> roleNames() const override { return {{NameRole, "name"}}; }  // #1
    };
    

    Main.qml:

    import QtQuick
    import QtQuick.Controls
    import Models
    
    ApplicationWindow {
        visible: true
        width: 640
        height: 480
        title: qsTr("HeaderView")
    
        VerticalHeaderView {
            id: vhv
            anchors.top: tv.top
            syncView: tv
            textRole: 'name' // #2
        }
    
        TableView {
            id: tv
            anchors.left: vhv.right
            anchors.top: parent.top
            anchors.right: parent.right
            anchors.bottom: parent.bottom
    
            columnSpacing: 1
            rowSpacing: 1
    
            model: TableModel {}
    
            delegate: Rectangle {
                implicitWidth: 40
                implicitHeight: 20
                color: 'black'
                Label {
                    anchors.fill: parent
                    text: name // #3
                    color: 'white'
                    horizontalAlignment: Label.AlignHCenter
                    verticalAlignment: Label.AlignVCenter
                }
            }
        }
    }
    

    When I run this, the app crashes with:

    appMatrixView(27748,0x1f5466180) malloc: *** error for object 0xc01927bf8: pointer being freed was not allocated
    appMatrixView(27748,0x1f5466180) malloc: *** set a breakpoint in malloc_error_break to debug
    [1]    27748 abort
    

    Everything works, if I change the lines in the code like this:

    • delete line #1 and #2
    • change line #3 to:
    text: display
    

    Whats goint on there? Any help is very appreciated!

    Cheers!

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      One thing I would do is to return a QVariant() rather than an empty string in your model data and headerData functions. I am not saying that this is the right solution but the model will be queried for more than a single role and not all of them uses strings.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      DuBuD 1 Reply Last reply
      0
      • JoeCFDJ Offline
        JoeCFDJ Offline
        JoeCFD
        wrote on last edited by
        #3

        Although I can build with meson and run your code on Ubuntu 22.04, TableModel needs Q_OBJECT macro.
        qmake6 --version
        QMake version 3.1
        Using Qt version 6.11.1 in /opt/Qt6/6.11.1/gcc_64/lib

        DuBuD 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          One thing I would do is to return a QVariant() rather than an empty string in your model data and headerData functions. I am not saying that this is the right solution but the model will be queried for more than a single role and not all of them uses strings.

          DuBuD Offline
          DuBuD Offline
          DuBu
          wrote on last edited by
          #4

          @SGaist said in Crash with Qt6.11.1 and VerticalHeaderView:

          Hi,

          One thing I would do is to return a QVariant() rather than an empty string in your model data and headerData functions. I am not saying that this is the right solution but the model will be queried for more than a single role and not all of them uses strings.

          This is just a minimal example. The string will be implicitly converted to a QVariant, but with an empty QVariant() I get QML warnings for the line marked with //#3 ("Can't convert undefined to string"). I also added a "qDebug() << role" line to data() to see what roles this function get called with and since I have only one role "NameRole" it only get called with this role only. But anyway it doesn't fix the crash.

          1 Reply Last reply
          0
          • JoeCFDJ JoeCFD

            Although I can build with meson and run your code on Ubuntu 22.04, TableModel needs Q_OBJECT macro.
            qmake6 --version
            QMake version 3.1
            Using Qt version 6.11.1 in /opt/Qt6/6.11.1/gcc_64/lib

            DuBuD Offline
            DuBuD Offline
            DuBu
            wrote on last edited by DuBu
            #5

            @JoeCFD said in Crash with Qt6.11.1 and VerticalHeaderView:

            Although I can build with meson and run your code on Ubuntu 22.04, TableModel needs Q_OBJECT macro.
            qmake6 --version
            QMake version 3.1
            Using Qt version 6.11.1 in /opt/Qt6/6.11.1/gcc_64/lib

            I use Qt 6.11.1 on macOS. This project is a cmake project and was created with the project template of Qt Creator. The lines I showed are the only changes I made. And building works fine, it just doesn't run.
            Are you sure about the Q_OBJECT? I thought Q_OBJECT is only needed, when I use Q_PROPERTY, signals or slots. But anyway, adding Q_OBJECT doesn't stop it from crashing.

            JoeCFDJ 1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Can you test with 6.12 ?

              I just did and your code is working without issue.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              DuBuD 1 Reply Last reply
              0
              • SGaistS SGaist

                Can you test with 6.12 ?

                I just did and your code is working without issue.

                DuBuD Offline
                DuBuD Offline
                DuBu
                wrote on last edited by
                #7

                @SGaist said in Crash with Qt6.11.1 and VerticalHeaderView:

                Can you test with 6.12 ?

                I just did and your code is working without issue.

                6.12.0-beta2?

                SGaistS DuBuD 2 Replies Last reply
                0
                • DuBuD DuBu

                  @SGaist said in Crash with Qt6.11.1 and VerticalHeaderView:

                  Can you test with 6.12 ?

                  I just did and your code is working without issue.

                  6.12.0-beta2?

                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @DuBu yes please.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • DuBuD DuBu

                    @SGaist said in Crash with Qt6.11.1 and VerticalHeaderView:

                    Can you test with 6.12 ?

                    I just did and your code is working without issue.

                    6.12.0-beta2?

                    DuBuD Offline
                    DuBuD Offline
                    DuBu
                    wrote on last edited by
                    #9

                    @DuBu said in Crash with Qt6.11.1 and VerticalHeaderView:

                    @SGaist said in Crash with Qt6.11.1 and VerticalHeaderView:

                    Can you test with 6.12 ?

                    I just did and your code is working without issue.

                    6.12.0-beta2?

                    It seems, I can't:

                    Undefined symbols for architecture arm64:
                      "QQmlPrivate::AOTLookupValidation::validateLookupSignature(QQmlEngine*, QV4::CompiledData::CompilationUnit*, QQmlPrivate::AOTLookupValidation::Lookup const&, std::variant<QQmlPrivate::AOTLookupValidation::PropertySignature, QQmlPrivate::AOTLookupValidation::EnumKeySignature, QQmlPrivate::AOTLookupValidation::MethodSignature> const&)", referenced from:
                          QmlCacheGeneratedCode::_qt_qml_MatrixView_Main_qml::validateLookupSignatures(QQmlEngine*, QV4::CompiledData::CompilationUnit*) in appMatrixView_Main_qml.cpp.o
                    ld: symbol(s) not found for architecture arm64
                    collect2: error: ld returned 1 exit status
                    
                    1 Reply Last reply
                    0
                    • DuBuD DuBu

                      @JoeCFD said in Crash with Qt6.11.1 and VerticalHeaderView:

                      Although I can build with meson and run your code on Ubuntu 22.04, TableModel needs Q_OBJECT macro.
                      qmake6 --version
                      QMake version 3.1
                      Using Qt version 6.11.1 in /opt/Qt6/6.11.1/gcc_64/lib

                      I use Qt 6.11.1 on macOS. This project is a cmake project and was created with the project template of Qt Creator. The lines I showed are the only changes I made. And building works fine, it just doesn't run.
                      Are you sure about the Q_OBJECT? I thought Q_OBJECT is only needed, when I use Q_PROPERTY, signals or slots. But anyway, adding Q_OBJECT doesn't stop it from crashing.

                      JoeCFDJ Offline
                      JoeCFDJ Offline
                      JoeCFD
                      wrote on last edited by
                      #10

                      @DuBu your model will not update in your qml gui without Q_OBJECT macro in TableModel. I did not change anything in your code and it works on ubuntu .

                      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
                      • Unsolved