QObject derivated Class copyable
-
Hello,
I found a good piece of software: https://code.google.com/p/cellardoor/
It has a datamodel class winedata which inherits from qobject and uses the property functionality for interact with qml.
Now the curiosity i dont understand:
Line 65 in controller.cpp he instaniate the template database as type of WineData
m_database(Database<WineData>::instance(this))
But WineData inherits from QObject and the copy and assignment is private
why does e.g. the function fillUpType and retrieveTypes function?I didn't get it to work.
http://qt-project.org/doc/qt-5/QObject.html
Here is also mentioned to use QObject subclasses in lists only with pointers.Code copied from database.cpp line 232
@
template <class Type>
Type Database<Type>::fillUpType(const QSqlRecord &record) const
{
Type item;QStringList list;
Utils::extractObjectProperties(item.metaObject(), &list, false, DB_PREFIX);
foreach (const QString &property, list) {
item.setProperty(qPrintable(property), record.value(QString(property).remove(DB_PREFIX)));
}return item;
}template <class Type>
QList<Type> Database<Type>::retrieveTypes(Filter arg) const
{
QList<Type> wineList;if (!m_wineModel) {
qCritical() << "Unable to insert a wine";
goto exit;
}if (arg == OrderByAgeDesc) {
m_wineModel->setSort(4, Qt::DescendingOrder);
}
m_wineModel->select();for (int i = 0; i < m_wineModel->rowCount(); ++i) {
const QSqlRecord record = m_wineModel->record(i);
wineList << fillUpType(record);
}exit:
return wineList;
}
@Greets
Tobi -
I got it, its possible because he defines a new assignment and copy operator/constructor himself for the QObject derivated class.
-
Hi,
However it's still wrong. He should rather have a clone function that creates a new object and then set all parameters on it. Disabling the copy of QObject is not done for nothing.