QT Eigenes Model wird nicht angezeigt

Ich hab mir mein eigenes TableModel geschrieben, aber es wird weder der Header noch der Inhalt angezeigt. Woran kann das liegen?

Model

 * Created on 06.01.2010
 *
 * Copyright (c) 2009, Kay Czarnotta
 *
 * All rights reserved.
 */
#ifndef SIGNALTABLEMODEL_H
#define SIGNALTABLEMODEL_H

#include <QAbstractItemModel>
#include <QVector>

#include "TSignal.h"

class SignalTableModel : public QAbstractItemModel
{
public:
    SignalTableModel();

    QModelIndex index(int row, int column, const QModelIndex & parent = QModelIndex() ) const;
    QModelIndex parent(const QModelIndex& index ) const;
    int rowCount(const QModelIndex& parent = QModelIndex()) const;
    int columnCount(const QModelIndex& parent = QModelIndex() ) const;
    QVariant data(const QModelIndex& index, int role = Qt::DisplayRole ) const;
    bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole );
    Qt::ItemFlags flags(const QModelIndex& index ) const;
    QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const;

    void addSignal(int column, Signal* sig);
    void setColumnCount(int count);

protected:
    QVector< QVector<Signal*>* >* tableData;
    QVector<QString> header;
};

#endif // SIGNALTABLEMODEL_H
/*
 * Created on 06.01.2010
 *
 * Copyright (c) 2009, Kay Czarnotta
 *
 * All rights reserved.
 */
#include "SignalTableModel.h"
#include "Settings.h"

#include <QModelIndex>
#include <QDebug>

SignalTableModel::SignalTableModel()
{
    tableData = new QVector< QVector<Signal*>* >();
}

QModelIndex SignalTableModel::index(int row, int column, const QModelIndex& parent) const
{
    qDebug()<< "[M] index (" << row << "," << column << ") " << parent;
    QModelIndex index;
    if(tableData->count() > column && tableData->at(column)->count() > row)
        index = createIndex(row, column, tableData->at(column)->at(row));
    qDebug() << "[R] Index " << index;
    return index;
}

QModelIndex SignalTableModel::parent(const QModelIndex& index ) const
{
    qDebug()<< "[M] parent " << index;

    QModelIndex ret;
    if(tableData->count()>index.column() && tableData->at(index.column())->count()>index.row()
       && index.row() > 0)
        ret = createIndex(index.row()-1, index.column(), tableData->at(index.column())->at(index.row()-1));

    qDebug() << "[R] Parent " << ret;
    return ret;
}

int SignalTableModel::rowCount(const QModelIndex& parent) const
{
    qDebug()<< "[M] rowCount "<< parent;

    int rowCount = 0;
    if(tableData->count() > parent.column() && parent.column() >= 0)
        rowCount = tableData->at(parent.column())->count();
    qDebug() << "[R] RowCount: " << rowCount;
    return rowCount;
}

int SignalTableModel::columnCount(const QModelIndex& parent) const
{
    qDebug()<< "[M] columnCount "<< parent;
    int colCount = tableData->count();
    qDebug() << "[R] ColumnCount: " << colCount;
    return colCount;
}

QVariant SignalTableModel::data(const QModelIndex& index, int role) const
{
    if(tableData->count()<=index.column() || tableData->at(index.column())->count()<=index.row())
        return "";

    Signal* sig = tableData->at(index.column())->at(index.row());
    if(index.column()%2==0)
        return sig->getRacer();
    else
        return sig->getTime();
}

bool SignalTableModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
    if(tableData->count()<=index.column() || tableData->at(index.column())->count()<=index.row())
        return false;

    if(index.column()%2==0)
    {
        QString s = value.toString();
        tableData->at(index.row())->at(index.row())->setRacer(s);
    }
    emit dataChanged(index, index);
    return true;
}

Qt::ItemFlags SignalTableModel::flags(const QModelIndex& index ) const
{
    if(index.column()%2==0)
        return Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsEditable;
    else
        return Qt::ItemIsSelectable | Qt::ItemIsEnabled;
}

QVariant SignalTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
    qDebug()<< "[M] headerData "<< section << "," << orientation << "," << role;
    qDebug() << "[R] Header: " << header.at(section);
    return header.at(section);
}

void SignalTableModel::addSignal(int column, Signal* sig)
{
    if(tableData->count()<=column)
        return;

    tableData->at(column)->append(sig);

    QModelIndex index = createIndex(column, tableData->at(column)->count(), sig);
    emit dataChanged(index, index);
    reset();
}

void SignalTableModel::setColumnCount(int count)
{
    if(tableData->count()!=0)
    {
        for(int i=0;i<tableData->count();i++)
            delete tableData->at(i);
        tableData->clear();
        header.clear();
    }
    for(int i=0;i<count;i++)
    {
        tableData->append(new QVector<Signal*>());
        QString s = "abc " + QString::number(i);
        //setHeaderData(i,Qt::Horizontal,i/*%2==0?"":Settings::getSlotName(i)*/, Qt::DisplayRole);
        header.append(s/*%2==0?"":Settings::getSlotName(i)*/);
    }
    reset();
    emit headerDataChanged(Qt::Horizontal, 0, count);
}

Verwendet wirds hier

    qDebug() << "+++++++++++++++++++++++++++++++";
    this->signalTimeModel = new SignalTableModel();
    this->ui->timesTable->setModel(signalTimeModel);
    qDebug() << "...............................";

    qDebug() << "------------------------";
    signalTimeModel->setColumnCount(colCount);
    qDebug() << "========================";

hier mal die Konsolenausgaben meiner Anwendung, vielleicht helfen die jemandem


+++++++++++++++++++++++++++++++
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
[M] rowCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] RowCount:  0
[M] rowCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] RowCount:  0
[M] rowCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] RowCount:  0
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
[M] columnCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] ColumnCount:  0
[M] columnCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] ColumnCount:  0
[M] columnCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] ColumnCount:  0
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
[M] index ( 0 , 0 )  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] Index  QModelIndex(-1,-1,0x0,QObject(0x0) )
...............................
------------------------
[M] rowCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] RowCount:  0
[M] rowCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] RowCount:  0
[M] columnCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] ColumnCount:  8
[M] columnCount  QModelIndex(-1,-1,0x0,QObject(0x0) )
[R] ColumnCount:  8
[M] headerData  0 , 1 , 13
[R] Header:  "abc 0"
[M] headerData  1 , 1 , 13
[R] Header:  "abc 1"
[M] headerData  2 , 1 , 13
[R] Header:  "abc 2"
[M] headerData  3 , 1 , 13
[R] Header:  "abc 3"
[M] headerData  4 , 1 , 13
[R] Header:  "abc 4"
[M] headerData  5 , 1 , 13
[R] Header:  "abc 5"
[M] headerData  6 , 1 , 13
[R] Header:  "abc 6"
[M] headerData  7 , 1 , 13
[R] Header:  "abc 7"
========================
SerialPortThread Created
Hardware Controller created
Object::connect: No such signal QTableView::cellChanged(int,
pp:72
Object::connect:  (sender name:   'timesTable')
Object::connect:  (receiver name: 'MainWindow')
[M] headerData  0 , 1 , 13
[R] Header:  "abc 0"
[M] headerData  1 , 1 , 13
[R] Header:  "abc 1"
[M] headerData  2 , 1 , 13
[R] Header:  "abc 2"
[M] headerData  3 , 1 , 13
[R] Header:  "abc 3"
[M] headerData  4 , 1 , 13
[R] Header:  "abc 4"
[M] headerData  5 , 1 , 13
[R] Header:  "abc 5"
[M] headerData  6 , 1 , 13
[R] Header:  "abc 6"
[M] headerData  7 , 1 , 13
[R] Header:  "abc 7"
[M] headerData  0 , 1 , 13
[R] Header:  "abc 0"
[M] headerData  1 , 1 , 13
[R] Header:  "abc 1"
[M] headerData  2 , 1 , 13
[R] Header:  "abc 2"
[M] headerData  3 , 1 , 13
[R] Header:  "abc 3"
[M] headerData  4 , 1 , 13
[R] Header:  "abc 4"
[M] headerData  5 , 1 , 13
[R] Header:  "abc 5"
[M] headerData  6 , 1 , 13
[R] Header:  "abc 6"
[M] headerData  7 , 1 , 13
[R] Header:  "abc 7"

So auf Anhieb würd ich sagen Du hast auch keine Daten zum anzeigen ausser einen QVector der leere QVectoren enthält. Warum der Header aber nicht angezeigt wird kann ich allerdings nicht so recht erkennen da es meiner Meinung nach richtig ist wie Du es es machst (überschreiben von headerData(int, Qt:: Orientation, int)).

Gut Schuß
VuuRWerK :wink: