Bonjour,

J'ai repris le tutoriel de carnet d'adresse disponible dans les tuto QT, et j'essaie de le modifié afin de mieux comprendre QT.
Dans le tutoriel la liste des contact est une QList de QPair, dans mon code j'ai mis une QList d'objet voici mon code :

contactmodel.h :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
class Contact:public QObject
{
    public:
    //Constructors
 
    Contact(QString & name): my_name(name){}
    Contact(QString & name, QString & phone): my_name(name), my_phone(phone){}
    Contact(QString & name, QString & phone, QString & email): my_name(name), my_phone(phone), my_email(email){}
 
    void setPhoneNb(QString);
    void setEmail(QString);
    QList <QString> getDatas();
    QString getName(){return my_name;}
    QString getPhone(){return my_phone;}
    QString getMail(){return my_email;}
 
    private:
    QString my_name;
    QString my_phone;
    QString my_email;
};
class ContactModel : public QAbstractTableModel
{
    Q_OBJECT
 
    public:
    //Constructor
    ContactModel(QObject *parent);
 
    //Functions:
    int rowCount(const QModelIndex &parent) const;
    QVariant data(const QModelIndex &index, int role) const;
 
    private:
    //QList<QString, QString, QString> listOfContacts; //Name, phoneNb, email
    QList <Contact> listOfContacts;
    int nbContact;
};
contactmodel.cpp:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
QVariant ContactModel::data(const QModelIndex &index, int role) const
{
    if(!index.isValid())
        return QVariant();
 
    if(index.row() >= listOfContacts.size()|| index.row())
        return QVariant();
 
    if (role == Qt::DisplayRole)
    {
        Contact & aContact = listOfContacts.at(index.row);
        switch(index.column())
        {
            case 0:
                return aContact.getName();
            case 1:
                return aContact.getPhone();
            case 2:
                return aContact.getMail();
        }
    }
J'ai une erreur à la compilation ligne : Contact & aContact = listOfContacts.at(index.row); voici ce qu'il me dit :
contactmodel.cpp:41: erreur: no matching function for call to «QList<Contact>::at(<unresolved overloaded function type>) const»

qtsdk-2009.03/qt/include/QtCore/qlist.h:394: note: candidats sont: const T& QList<T>::at(int) const [with T = Contact]
Quelqu'un pourrait il m'expliquer/aider

SVP

MErci d'avance