Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QObject derivated Class copyable

QObject derivated Class copyable

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    tobias.h
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.h
      wrote on last edited by
      #2

      I got it, its possible because he defines a new assignment and copy operator/constructor himself for the QObject derivated class.

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved