Swears at the class, I can not understand the reasons:

#ifndef SETMAIL_H #define SETMAIL_H #include <QObject> #include "class_mail/_class_mail.h" class SetMail : public QObject { Q_OBJECT public: explicit SetMail(QObject *parent = 0); QString sender; // ΠΊΠΎΠΌΡƒ QString provider; // ΠΎΡ‚ ΠΊΠΎΠ³ΠΎ QString theme; // Ρ‚Π΅ΠΌΠ° письма QString file_letter; // Ρ‚Π΅Π»ΠΎ письма QString file_attach; // ΠΏΡ€ΠΈΠ»ΠΎΠΆΠ΅Π½ΠΆΠΈΠ΅ ΠΊ ΠΏΠΈΡΡŒΠΌΡƒ int subscribeId; // id подписки signals: public slots: private: void test (); }; #endif // SETMAIL_H #include "setmail.h" SetMail::SetMail(QObject *parent) : QObject(parent) { } void SetMail::test() { subscribeId = 0; } 

Errors:

 error: use of deleted function 'SetMail::SetMail(const SetMail&)' case 0: _t->setMail((*reinterpret_cast< SetMail(*)>(_a[1]))); break; ^ /Qt/5.6/gcc_64/include/QtCore/qobject.h:461: error: 'QObject::QObject(const QObject&)' is private Q_DISABLE_COPY(QObject) ^ error: within this context class SetMail : public QObject ^ error: use of deleted function 'QObject::QObject(const QObject&)' 

    1 answer 1

    For objects inherited from QObject copy constructor and the copy assignment operator are not generated, because they are disabled in QObject using the Q_DISABLE_COPY macro Q_DISABLE_COPY For example:

     class A : public QObject{ }; void foo(){ A a1; A a2 = a1; //Ошибка A a3; a3 = a1; //Ошибка } 

    There are two ways to solve the problem. The first is to write the missing methods yourself:

     class A : public QObject{ public: A(const A &other): QObject(other.parent()) {} A& operator=(const A &other){ return *this; } }; void foo(){ A a1; A a2 = a1; //Π Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ A a3; a3 = a1; //Π Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ } 

    True in this case, the copy of the object will not have all the signal-slot connections

    The second is to avoid copying and using pointers.

     class A : public QObject{ }; void foo(QObject *parent){ A *a1 = new A(parent); A *a2 = a1; //Π Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ A *a3 = new A(parent); a3 = a1; //Π Π°Π±ΠΎΡ‚Π°Π΅Ρ‚ } 

    UPD: For your class, you get something like this:

     class SetMail : public QObject{ Q_OBJECT public: QString sender; QString provider; QString theme; QString file_letter; QString file_attach; int subscribeId; explicit SetMail(QObject *parent = 0): QObject(parent) {} SetMail(const SetMail &other): QObject(other.parent()), sender(other.sender), provider(other.provider), theme(other.theme), file_letter(other.file_letter), file_attach(other.file_attach), subscribeId(other.subscribeId) {} SetMail& operator=(const SetMail &other){ sender = other.sender; provider = other.provider; theme = other.theme; file_letter = other.file_letter; file_attach = other.file_attach; subscribeId = other.subscribeId; } //... }; 
    • Added: SetMail (const SetMail & other): QObject (other.parent ()) {} SetMail & operator = (const SetMail & other) {return * this; } Issued errors: /moc_mainwindow.cpp:106: Reference: `MainWindow :: providerNOW () 'Swears at: case 7: _t-> providerNOW (); break; : -1: error: collect2: error: ld returned 1 exit status - shaman888
    • Is it possible to specify the solution in my example? - shaman888
    • one
      @ shaman888, the linker cannot find an implementation of the providerNOW() method. By the way, since it came to a hitch, this means that we have corrected the previous error. - yrHeTaTeJlb
    • Thank you for your reply. I added the implementation of the providerNOW () slot, the error disappeared, your version will be credited, but I would like to see the implementation of my example in the answer. - shaman888
    • @ shaman888, updated - yrHeTaTeJlb