'QObject :: QObject(const QObject&)'是私有的

时间:2015-03-17 19:10:37

标签: c++ qt private qobject

我收到了错误:

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
   ^

我已经阅读了很多关于它的内容,但实际上我不知道我的情况有什么问题。我知道QObject构造函数不可复制,但我不是在这里做的。或者实际上我不知道我在做它^^。这是我的代码: 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];
    }
}

感谢您的帮助

1 个答案:

答案 0 :(得分:3)

您只需阅读Q_DISABLE_COPY

的文档即可
  

禁止使用给定类的复制构造函数和赋值运算符。

     

不应将QObject的子类实例视为值   可以复制或分配,但作为唯一身份。这意味着   当你创建自己的QObject子类(导演或者   间接),你不应该给它一个复制构造函数或赋值   运营商。但是,仅仅省略它们可能还不够   class,因为,如果你错误地写了一些需要复制的代码   构造函数或赋值运算符(很容易做到),编译器   会为您精心创造它。你必须做得更多。

     

好奇的用户会看到Qt类派生自   QObject通常在私有部分中包含此宏:

class MyClass : public QObject
{

  private:
    Q_DISABLE_COPY(MyClass)
};