nategoofs
13th August 2007, 00:00
Im trying to add elements to a QAbstractTableModel via the QVariant data function like so
QVariant WTrackTableModel :: data(const QModelIndex &index, int role) const
{
TrackInfoObject *m_pTrackInfo = m_pTrackCollection->getTrack(index.row());
QStringList trackInfoList;
trackInfoList.append(m_pTrackInfo->getScoreStr());
trackInfoList.append(m_pTrackInfo->getTitle());
trackInfoList.append(m_pTrackInfo->getArtist());
trackInfoList.append(m_pTrackInfo->getType());
trackInfoList.append(m_pTrackInfo->getDurationStr());
trackInfoList.append(m_pTrackInfo->getBitrateStr());
trackInfoList.append(m_pTrackInfo->getBpmStr());
trackInfoList.append(m_pTrackInfo->getComment());
if (!index.isValid())
return QVariant();
if (index.row() >= m_pTrackCollection->getSize())
return QVariant();
if (role == Qt::DisplayRole)
return trackInfoList;
else
return QVariant();
}
This code causes my program to crash. What I'm aiming to do is place the trackinfoobject's various get functions QString information into their respective columns (score, title, artist, etc.) what do I need to change to do so?
Thanks!
QVariant WTrackTableModel :: data(const QModelIndex &index, int role) const
{
TrackInfoObject *m_pTrackInfo = m_pTrackCollection->getTrack(index.row());
QStringList trackInfoList;
trackInfoList.append(m_pTrackInfo->getScoreStr());
trackInfoList.append(m_pTrackInfo->getTitle());
trackInfoList.append(m_pTrackInfo->getArtist());
trackInfoList.append(m_pTrackInfo->getType());
trackInfoList.append(m_pTrackInfo->getDurationStr());
trackInfoList.append(m_pTrackInfo->getBitrateStr());
trackInfoList.append(m_pTrackInfo->getBpmStr());
trackInfoList.append(m_pTrackInfo->getComment());
if (!index.isValid())
return QVariant();
if (index.row() >= m_pTrackCollection->getSize())
return QVariant();
if (role == Qt::DisplayRole)
return trackInfoList;
else
return QVariant();
}
This code causes my program to crash. What I'm aiming to do is place the trackinfoobject's various get functions QString information into their respective columns (score, title, artist, etc.) what do I need to change to do so?
Thanks!