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. Call to Implicitly deleted copy constuctor; How can I structure this class properly?
Forum Updated to NodeBB v4.3 + New Features

Call to Implicitly deleted copy constuctor; How can I structure this class properly?

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 5 Posters 3.8k 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.
  • S Offline
    S Offline
    Smeeth
    wrote on last edited by Smeeth
    #1
    This post is deleted!
    JonBJ VRoninV 2 Replies Last reply
    0
    • M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      @Smeeth said in Call to Implicitly deleted copy constuctor; How can I structure this class properly?:

      public:
           FileInfo(QFileInfo fileInfo);
      

      I guess you mean FileWriter ...

      I suspect this is because I am storing a QFile* which doesn't have a copy constructor?

      You're right, QFile derives from QObject which is uncopyable.

      It's clearly explain in the QObject doc:

      No Copy Constructor or Assignment Operator
      QObject has neither a copy constructor nor an assignment operator. This is by design.
      The main consequence is that you should use pointers to QObject (or to your QObject subclass)
      where you might otherwise be tempted to use your QObject subclass as a value.
      For example, without a copy constructor, you can't use a subclass of QObject as the value to be stored in one of the container classes.
      You must store pointers.

      1 Reply Last reply
      3
      • S Smeeth

        This post is deleted!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @Smeeth
        As @mpergand says, you cannot copy.

        So in the case of a function parameter, FileWriter::FileWriter(QFileInfo fileInfo), you could either define yours as taking a QFileInfo *fileInfo, or more usually/easier/like the way Qt functions tend to pass QObjects around, use a reference: QFileInfo &fileInfo.

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

          @JonB QFileInfo is not a QObject based class you can see that on the top of the documentation. There's no inherits field in the table and furthermore there's a copy constructor and an assignment operator. That said, using const QFileInfo & as parameter type for the constructor will avoid a useless copy.

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

          JonBJ 1 Reply Last reply
          1
          • SGaistS SGaist

            @JonB QFileInfo is not a QObject based class you can see that on the top of the documentation. There's no inherits field in the table and furthermore there's a copy constructor and an assignment operator. That said, using const QFileInfo & as parameter type for the constructor will avoid a useless copy.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by
            #5

            @SGaist
            Sorry, I mis-read QFileInfo for QFile. Re-reading carefully, where in OP's code is the

            when I try to return that object from a method

            ?

            Anyway, if you feel my posts are confusing this issue please feel free to delete them.

            1 Reply Last reply
            0
            • S Smeeth

              This post is deleted!

              VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              @Smeeth said in Call to Implicitly deleted copy constuctor; How can I structure this class properly?:

              This is giving me a "Call to Implicitly deleted copy constructor" error when I try to return that object from a method.

              What object? what method?

              const static QString NEW_LINE;

              This is useless, replace stream<< FileWriter::NEW_LINE; with stream<< endl;. See http://doc.qt.io/qt-5/qtextstream.html#endl

              if (!file->open(QIODevice::WriteOnly))

              If you are intending to write text, open the file in text modeif (!file->open(QIODevice::WriteOnly | QIODevice::Text))

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              2

              • Login

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