IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Discussion :

fonction at() de QList

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 22
    Par défaut fonction at() de QList
    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

  2. #2
    Rédacteur

    Inscrit en
    Novembre 2006
    Messages
    1 272
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 272
    Par défaut
    C'est normal c'est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Contact & aContact = listOfContacts.at(index.row());
    Bon courage pour la suite.
    Vous voulez participer aux Tutoriels, FAQ ou Traductions et faire partie de l'équipe Qt de Developpez.
    N'hésitez pas à me contacter par MP.

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 22
    Par défaut
    La boulette !
    Merci !

    Mais j'ai une autre erreur :
    /home/superman/QT4/synchro_contact/contactmodel.cpp:41: erreur: invalid initialization of reference of type «Contact&» from expression of type «const Contact»
    Dans le tuto ils font : QPair<QString, QString> pair = listOfPairs.at(index.row());

  4. #4
    Rédacteur

    Inscrit en
    Novembre 2006
    Messages
    1 272
    Détails du profil
    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 272
    Par défaut
    Si tu ecris cela ca fonctionne ou pas ?
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Contact  aContact = listOfContacts.at(index.row());
    Vous voulez participer aux Tutoriels, FAQ ou Traductions et faire partie de l'équipe Qt de Developpez.
    N'hésitez pas à me contacter par MP.

  5. #5
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 22
    Par défaut
    Non ca ne fonctionne pas :

    J'ai 3 erreurs :

    /home/superman/QT4/synchro_contact/../../qtsdk-2009.03/qt/include/QtCore/qobject.h:302: erreur: «QObject::QObject(const QObject&)» is private

    /home/superman/QT4/synchro_contact/contactmodel.h:14: erreur: à l'intérieur du contexte

    /home/superman/QT4/synchro_contact/contactmodel.cpp:41: note: synthesized method «Contact::Contact(const Contact&)» first required here

    ligne 14 du .h est le '{' après : class Contact:public QObject

    ligne 41 est la ligne où il y a le at()

  6. #6
    Membre averti
    Profil pro
    Inscrit en
    Septembre 2008
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2008
    Messages : 22
    Par défaut 'ti up
    Pass d'idée ?

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 8
    Dernier message: 12/02/2013, 01h08
  2. Fonction API
    Par margilb dans le forum C++Builder
    Réponses: 2
    Dernier message: 08/07/2002, 11h11
  3. Implémentation des fonctions mathématiques
    Par mat.M dans le forum Mathématiques
    Réponses: 9
    Dernier message: 17/06/2002, 16h19
  4. fonction printf
    Par ydeleage dans le forum C
    Réponses: 7
    Dernier message: 30/05/2002, 11h24
  5. FOnction api specifiant la position de la souris
    Par florent dans le forum C++Builder
    Réponses: 4
    Dernier message: 15/05/2002, 20h07

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo