2015-03-17 2 views
1

Je reçois l'erreur:« QObject :: QObject (const & QObject) » est privé

C:\Qt\5.3\mingw482_32\include\QtCore\qobject.h:465: error : 'QObject::QObject(const QObject&)' is private 
    Q_DISABLE_COPY(QObject) 
        ^
Qt\MyMediaLibraries\MyMediaLibraries\cpp.films\Movie.h:10: error : within this context 
class Movie: public QObject 
^

J'ai lu beaucoup à ce sujet, mais vraiment je ne sais pas ce qui ne va pas dans mon cas. Je sais que le constructeur QObject n'est pas copiable, mais je ne le fais pas ici. Ou en fait je ne sais pas je le fais ^^. Voici mon code: Movie.h:

class Movie: public QObject 
{ 

    Q_OBJECT 

public: 
    Movie(); 
    Movie(const int &movie_id, const QString &movie_title, const QString &movie_md5, const QDate &movie_releaseDate, const QString &movie_genre, 
      const int &movie_note, const bool &movie_alreadySeen, const bool &movie_favourite, const bool &movie_toBeSeen, 
      const QString &movie_synopsis, const int &movie_duration, const QString &movie_backdropPath, const QString &movie_path, 
      const QString &movie_backdropMD5, const QString &movie_posterMD5, const QString &movie_posterPath, const QString &movie_collection); 
    void getInfos(); 

    //TheMovieDB *tmdb; 

    int id; 
    QString title; 
    QDate releaseDate; 
    QString genre; 
    int note; 
    bool alreadySeen; 
    bool favourite; 
    bool toBeSeen; 
    QString synopsis; 
    int duration; 
    QString path; 
    QString md5; 
    QString backdropPath; 
    QString backdropMD5; 
    QString posterPath; 
    QString posterMD5; 
    QString collection; 

public slots: 
    void updateDatas(); 
}; 

Movie.cpp:

Movie::Movie() 
{ 
    title = ""; 
    md5 = ""; 
    id = 0; 
    path = ""; 
    releaseDate = QDate(); 
    genre = ""; 
    note = 0; 
    alreadySeen = false; 
    favourite = false; 
    toBeSeen = false; 
    synopsis = ""; 
    duration = 0; 
    backdropPath = ""; 
    backdropMD5 = ""; 
    posterPath = ""; 
    posterMD5 = ""; 
    collection = ""; 
} 

Movie::Movie(const int &movie_id, const QString &movie_title, const QString &movie_md5, const QDate &movie_releaseDate, 
      const QString &movie_genre, const int &movie_note, const bool &movie_alreadySeen, const bool &movie_favourite, 
      const bool &movie_toBeSeen, const QString &movie_synopsis, const int &movie_duration, 
      const QString &movie_backdropPath, const QString &movie_path, const QString &movie_backdropMD5, 
      const QString &movie_posterMD5, const QString &movie_posterPath, const QString &movie_collection) 
{ 
    id = movie_id; 
    title = movie_title; 
    md5 = movie_md5; 
    path = movie_path; 
    releaseDate = movie_releaseDate; 
    genre = movie_genre; 
    note = movie_note; 
    alreadySeen = movie_alreadySeen; 
    favourite = movie_favourite; 
    toBeSeen = movie_toBeSeen; 
    synopsis = movie_synopsis; 
    duration = movie_duration; 
    backdropPath = movie_backdropPath; 
    backdropMD5 = movie_backdropMD5; 
    posterPath = movie_posterPath; 
    posterMD5 = movie_posterMD5; 
    collection = movie_collection; 
} 

void Movie::getInfos() 
{ 
    QObject::connect(tmdb , SIGNAL(dataRetrieved()) , this , SLOT(updateDatas())); 
    tmdb->search(title); 
} 


void Movie::updateDatas() 
{ 
    title = tmdb->t_infosList["title"].toString(); 
    md5 = ""; 
    id = tmdb->t_infosList["id"].toInt(); 
    path = ""; 
    releaseDate = tmdb->t_infosList["release_date"].toDate(); 
    note = tmdb->t_infosList["note"].toInt(); 
    synopsis = tmdb->t_infosList["overview"].toString(); 
    backdropPath = tmdb->t_infosList["backdrop"].toString(); 
    backdropMD5 = GeneralFunctions::hashMD5(tmdb->t_infosList["backdrop"].toString()); 
    posterPath = tmdb->t_infosList["poster"].toString(); 
    posterMD5 = GeneralFunctions::hashMD5(tmdb->t_infosList["poster"].toString()); 
    collection = tmdb->t_infosList["collection"].toString(); 

    QStringList genres = tmdb->t_infosList["genres"].toStringList(); 
    genre = genres[0]; 
    for(int i=0 ; i<genres.size() ; i++) 
    { 
     genre =genre + ", " + genres[i]; 
    } 
} 

Merci pour votre aide

+2

Votre fondement Tout le problème est que vous essayez de copier un objet Movie quelque part, mais ne pouvez pas le faire à cause de la classe de base. Désactivez également le constructeur de copie de votre film, puis le compilateur vous montrera exactement où se trouve la tentative de copie (si ce n'est pas déjà fait mais pas montré dans votre message d'erreur). – metal

+0

Sur une note de côté, ce second constructeur est tout simplement épouvantable. Créez simplement une structure 'MovieInfo', placez-en une dans la classe' Movie' pour la rendre plus propre et un constructeur qui en accepte une. – dtech

+0

ok je vais y réfléchir. Mais avoir une structure contenant toutes ces variables sera horrible. Et cela signifie que je devrai savoir quelles variables sont dans ma classe avant de l'utiliser. Utiliser une structure signifie que je n'ai pas besoin d'une classe ^^ (uniquement pour les fonctions). – Avatar36

Répondre

2

Vous devez simplement lire la documentation

Q_DISABLE_COPY

Disables the use of copy constructors and assignment operators for the given Class.

Instances of subclasses of QObject should not be thought of as values that can be copied or assigned, but as unique identities. This means that when you create your own subclass of QObject (director or indirect), you should not give it a copy constructor or an assignment operator. However, it may not enough to simply omit them from your class, because, if you mistakenly write some code that requires a copy constructor or an assignment operator (it's easy to do), your compiler will thoughtfully create it for you. You must do more.

The curious user will have seen that the Qt classes derived from QObject typically include this macro in a private section:

class MyClass : public QObject 
{ 

    private: 
    Q_DISABLE_COPY(MyClass) 
}; 
+0

Je ne comprends pas. Cela signifie que je ne devrais pas utiliser un constructeur surchargé? Je vais lire un peu à propos de Q_DISABLE_COPY parce que je ne comprends pas. – Avatar36

+0

'Q_DISABLE_COPY' déclaré dans' QObject'. Et vous utilisez 'QObject' comme classe de base. Vous ne devriez pas surcharger le constructeur de copie ni 'operator =' –

+0

Donc, c'est mon constructeur Movie() qui est faux? Je veux juste être capable d'attraper des signaux avec cette classe. Je n'ai aucun autre usage de la classe QObject. – Avatar36