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

'QObject::QObject(const QObject&)' is private

我遇到错误:

C:\Qt.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];
    }
}

感谢您的帮助

您只需阅读 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)
};