Hi all,
I am trying to get my head around the model/view way of programming. I am making a simple example using my own class, and have run into a problem. My own class is very simple at this stage, since I'm just trying to get it to work:
{
Q_OBJECT
public:
VfAlert( const VfAlert &alert );
};
{
Q_OBJECT
public:
VfAlertListModel
( const QList<VfAlert>
&alerts,
QObject *parent
= 0 )
// int rowCount(const QModelIndex &parent = QModelIndex()) const;
// QVariant data(const QModelIndex &index, int role) const;
// QVariant headerData(int section, Qt::Orientation orientation,
// int role = Qt::DisplayRole) const;
private:
QList<VfAlert> alertList;
};
class VfAlert : public QObject
{
Q_OBJECT
public:
VfAlert( QObject *parent = 0 ) : QObject( parent ) {}
VfAlert( const VfAlert &alert );
QString title;
};
class VfAlertListModel : public QAbstractListModel
{
Q_OBJECT
public:
VfAlertListModel( const QList<VfAlert> &alerts, QObject *parent = 0 )
: QAbstractListModel(parent), alertList(alerts) {}
// int rowCount(const QModelIndex &parent = QModelIndex()) const;
// QVariant data(const QModelIndex &index, int role) const;
// QVariant headerData(int section, Qt::Orientation orientation,
// int role = Qt::DisplayRole) const;
private:
QList<VfAlert> alertList;
};
To copy to clipboard, switch view to plain text mode
and the copy constructor for VfAlert:
VfAlert::VfAlert( const VfAlert &alert )
{
title = alert.title;
};
VfAlert::VfAlert( const VfAlert &alert )
{
title = alert.title;
};
To copy to clipboard, switch view to plain text mode
I had to add the copy constructor because without it, it wouldn't compile.
Now it compiles ok, but I get this warning:
warning: base class 'class QObject' should be explicitly initialized in the copy constructor
That sounds pretty serious, so I'm guessing I shouldn't ignore it, but can't get my head around what exactly I should be doing with a QObject in the copy constructor 
Any ideas?
Thanks
Bookmarks