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. [SOLVED] error: 'QObject::QObject(const QObject&)' is private
Qt 6.11 is out! See what's new in the release blog

[SOLVED] error: 'QObject::QObject(const QObject&)' is private

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 14.6k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    Hi all,

    i have this situation:

    @
    #include <QObject>

    class MeteoLocale: public QObject
    {
    Q_OBJECT

    public:
    MeteoLocale();
    virtual ~MeteoLocale();

    QList<MeteoLocale> underList;

    }@

    and this is the error that return:

    error: 'QObject::QObject(const QObject&)' is private

    exist a some kind of metod to do this?

    regard

    1 Reply Last reply
    0
    • S Offline
      S Offline
      steno
      wrote on last edited by
      #2

      The copy constructor is private, thus you have to use pointers in your list.

      @
      QList<MeteoLocale *>
      @

      1 Reply Last reply
      0
      • ? Offline
        ? Offline
        A Former User
        wrote on last edited by
        #3

        but i need to set value not pointer...

        1 Reply Last reply
        0
        • ? Offline
          ? Offline
          A Former User
          wrote on last edited by
          #4

          A QObject and it derivations are non-copyable (more specifically non-copy-constructible and non-assignable). The container classes, like QList, require a copyable type.

          Therefore you cannot create a QList of QObject objects. You will have to create a QList of pointer to QObject (<code>QList<MeteoaLocale *> underList</code>).

          1 Reply Last reply
          0
          • ? Offline
            ? Offline
            A Former User
            wrote on last edited by
            #5

            To complete Lukas Geyer answer, the reason why QObject cannot be copied nor assigned is because they are considered individuals: they can have a name, a parent, children and connections. As copying these all would not make sense, it was made impossible.

            Just allocate your objects with 'new' and fill your list with the returned pointers

            1 Reply Last reply
            0
            • ? Offline
              ? Offline
              A Former User
              wrote on last edited by
              #6

              Tanks to all guy, to solve i have decide to remove the QObject ensension and for interact whit QML i create another object whit the same property but extend QObject.

              Tnx to all

              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