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. base class QSortFilterProxyModel has private copy constructor
Qt 6.11 is out! See what's new in the release blog

base class QSortFilterProxyModel has private copy constructor

Scheduled Pinned Locked Moved General and Desktop
qsortfilterprox
4 Posts 2 Posters 2.5k Views 2 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.
  • M Offline
    M Offline
    mrenoch
    wrote on last edited by mrenoch
    #1

    Need help, I'm a Seasoned developer and I've been working with QML for about a year but I'm very new to C++ and I'm working on a project to convert a pyqt application to a pure C++ application. We have an app that is primarily all QML with several different sort/filter lists. In the existing pyqt app we can generate a QSortFilterProxyModel from QML and set it as the source model to any List within QML but I have so far failed to convert this functionality to a pure C++ solution. Here are the relevant code Snippets that I have so far:

    ::main.cpp

    int main(int argc, char *argv[])
    {
        QGuiApplication app(argc, argv);
        QQmlApplicationEngine engine;
        RootContext rrc;
        QQmlContext *rootContext = engine.rootContext();
        /*this lets me use a single rootContext QObject from C++ to have access to global properties and slots within the QML application*/
        rootContext->setContextObject(&rrc);
    
        engine.load(QUrl(QStringLiteral("(path to root .qml file)")));
        QObject *topLevel = engine.rootObjects().value(0);
        QQuickWindow *window = qobject_cast<QQuickWindow *>(topLevel);
    
        window->show();
    
        return app.exec();
    }
    

    :: rootContext.h

    #include <filtermodel.h>
    ...
    class RootContext : public QObject {
        Q_OBJECT
    public:
        explicit RootContext(QObject* parent = 0);
    public slots:
        // If I remove this slot from the header and the C++ then everything compiles ok
        FilterModel GetSortFilterModel(QObject *parent);
    };
    ...
    

    :: rootContext.cpp

    #include <filtermodel.h>
    ...
    RootContext::RootContext(QObject* parent)
        : QObject(parent)
    {
    }
    // This method causes the compile error: base class QSortFilterProxyModel has private copy constructor
    FilterModel RootContext::GetSortFilterModel(QObject *parent)
    {
        return new FilterModel(parent);
    }
    ...
    

    :: filtermodel.h

    #ifndef SORTFILTERMODEL_H
    #define SORTFILTERMODEL_H
    
    #include <QSortFilterProxyModel>
    
    
    class FilterModel: public QSortFilterProxyModel
    {
        Q_OBJECT
    public:
        FilterModel(QObject * parent  = 0);
    
        ~FilterModel();
    
    signals:
    
    public slots:
    };
    
    #endif // SORTFILTERMODEL_H
    

    :: filtermodel.cpp

    #include "filtermodel.h"
    
    FilterModel::FilterModel(QObject* parent): QSortFilterProxyModel(parent)
    {
    }
    
    FilterModel::~FilterModel()
    {
    }
    

    Then we can generate a new sortfilter model from QML which we currently do in the pyqt app all over the place like this:

    Component {
            Item {
                width: parent.width
                height: childrenRect.height
                property var filteredModel:  GetSortFilterModel(gridView)
                Binding {
                    target: filteredModel
                    property: 'source'
                    value:  (Pre-generated ListModel of items)
                }
    
                GridView {
                    id: gridView
                    model: filteredModel
                    width: parent.width
                    delegate: someDelegate
                }
            }
        }
    

    compile output:
    In file included from ..rootcontext.cpp:1:
    In file included from ..rootcontext.h:7:
    ../filtermodel.h:7:7: error: base class 'QSortFilterProxyModel' has private copy constructor
    class FilterModel: public QSortFilterProxyModel
    ^
    ../../../../Qt5.5/5.5/clang_64/lib/QtCore.framework/Headers/qsortfilterproxymodel.h:162:20: note: declared private here
    Q_DISABLE_COPY(QSortFilterProxyModel)
    ^
    .../Qt5.5/5.5/clang_64/lib/QtCore.framework/Headers/qglobal.h:1042:5: note: expanded from macro 'Q_DISABLE_COPY'
    Class(const Class &) Q_DECL_EQ_DELETE;
    ^
    ..rootcontext.cpp:57:5: note: implicit copy constructor for 'FilterModel' first required here
    return new FilterModel(parent);
    ^
    1 error generated.
    make: *** [rootcontext.o] Error 1
    14:27:04: The process "/usr/bin/make" exited with code 2.
    Error while building/deploying project Pumpernickel (kit: Desktop QT5.5)
    When executing step "Make"

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

      Hi,

      FilterModel RootContext::GetSortFilterModel(QObject *parent) should rather be FilterModel* RootContext::GetSortFilterModel(QObject *parent)

      Otherwise you are trying to copy a QObject derived class which is not possible.

      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
      1
      • M Offline
        M Offline
        mrenoch
        wrote on last edited by
        #3

        Thank you thank you, that totally works, It solved my compile error, I then started getting a runtime error in QML saying "unknown method return type FilterModel*" but once I regestered that type with QML its now working. Quick question, I'm currently registering that type in my main.cpp file like so:

        qmlRegisterType<FilterModel>("FilterModel", 1, 0, "FilterModel");

        I was just wondering if there was a way to include the type in the QML_IMPORT_PATH property or something, or if I'll just have to use the former example to register all my custom QObject types?

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

          You have to register your custom types

          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