Reputation: 31
I have a relatively simple class that contains a layout with a few widgets (labels, lineEdits, pushButtons) that gets displayed as a card. It all works fine until I try to add signals and slots. The header file, below, compiles fine with the sections commented-out as shown.
#include <QString>
#include <QObject>
#include <QWidget>
class KMLFile //: public QObject
{
//Q_OBJECT
public:
KMLFile();
~KMLFile();
QString m_originalFilename;
QString m_originalPath;
QString m_proposedFilename;
QString m_propsoedPath;
QString m_coords;
QWidget* trackWidget;
void populate(QString originalFilename, QString originalPath, QString proposedFilename, QString coords);
QString getCoords();
int getLength();
//public slots:
//void changeFilename();
};
When those bits of code are left in, I get the following error:
"C:...\qlist.h:425: error: C2280: 'KMLFile::KMLFile(const KMLFile &)': attempting to reference a deleted function
I am using Qt5.3 and Qt Creator. I have tried cleaning, running qmake and deleting the build folder to no avail. I'm stumped!
Grateful for any insight into how to fix this so that I can progress.
Upvotes: 2
Views: 7798
Reputation: 1907
QObject has a deleted copy constructor. Your class is creating a compiler generated copy constructor. When you make QObject
a base of your class the compiler generated copy constructor for KLMFile
attempts to call the deleted copy constructor of the base class and that is when you get an error.
The copy constructor for KLMFile
will be automatically generated if required (ie if you try copy an instance of the class) unless you explicitly specify a copy constructor of your own.
If the line referenced in the error is near a copy of the KLMFile
class that would be a strong indicator that this is the case.
Upvotes: 1
Reputation: 9725
The copy constructor of QObject
is private - or deleted.
Somewhere else in your code you use the copy constructor of KMLFile
, which then calls the copy constructor of QObject
.
You could reimplement the copy constructor of KMLFile
, but the best solution is to not use it at all.
In your QList
you should store pointers to the KMLFile
objects instead of the objects themselves provided that they will live longer than the list itself. Or you can start using QSharedPointer
.
Upvotes: 6