Crash with Qt6.11.1 and VerticalHeaderView
-
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 abortEverything works, if I change the lines in the code like this:
- delete line #1 and #2
- change line #3 to:
text: displayWhats goint on there? Any help is very appreciated!
Cheers!
-
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. -
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.@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.
-
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@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/libI 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. -
Can you test with 6.12 ?
I just did and your code is working without issue.
-
@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?
-
@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?
@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 -
@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/libI 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.