Hi.
First, sorry for my bad knowledge of C++ templates 
I have 2 classes: Street and Manager.
class Street
{
public:
Street();
~Street();
QMap<QString, QString> values; // ex: "id" => "1", "name" => "Paris"
....
};
class Street
{
public:
Street();
~Street();
QMap<QString, QString> values; // ex: "id" => "1", "name" => "Paris"
....
};
To copy to clipboard, switch view to plain text mode
class Manager
{
public:
Manager();
~Manager();
QMap<QString, QString> values; // ex: "id" => "1", "name" => "John"
....
};
class Manager
{
public:
Manager();
~Manager();
QMap<QString, QString> values; // ex: "id" => "1", "name" => "John"
....
};
To copy to clipboard, switch view to plain text mode
Now i have 2 QAbstractTableModel subclasses: one that works with streets and one for managers.
{
Q_OBJECT
public:
explicit StreetTableModel
(QObject *parent
= 0);
....
private:
QList<Street*> records; // Here we store the streets
....
};
class StreetTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit StreetTableModel(QObject *parent = 0);
....
private:
QList<Street*> records; // Here we store the streets
....
};
To copy to clipboard, switch view to plain text mode
{
Q_OBJECT
public:
explicit ManagerTableModel
(QObject *parent
= 0);
....
private:
QList<Manager*> records; // Here we store the managers
....
};
class ManagerTableModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit ManagerTableModel(QObject *parent = 0);
....
private:
QList<Manager*> records; // Here we store the managers
....
};
To copy to clipboard, switch view to plain text mode
In the future there will be a lot of objects like street and manager and i don't want to create each time a subclass of QAbstractTableModel.
Can you please show me a way to define a subclass of QAbstractTableModel using templates ? I tried some variants, but a don't get it how it must work.
I want to be able for example to create a model like:
TableModel<Street> *model = new TableModel();
TableModel<Street> *model = new TableModel();
To copy to clipboard, switch view to plain text mode
Thanks a lot.
Bookmarks