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. QFile - Problem with generated setter
Forum Updated to NodeBB v4.3 + New Features

QFile - Problem with generated setter

Scheduled Pinned Locked Moved Unsolved General and Desktop
18 Posts 5 Posters 1.9k 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.
  • B Offline
    B Offline
    buzz_lightzyear
    wrote on last edited by
    #1

    Hello!

    I have a problem with with a member in my program. I have created a lot of members, like QString, QDate, QImage and QFile. Then I have choosen "Create Getter and Setter Member Functions" and the Qt Creator implemented all the getters and setters for me - everything without problems except the QFile-setter. Qt creator shows me an error:

    Overload resolution selected deleted operator '='
    

    Here explicit error message:

    program.cpp:108:13: Overload resolution selected deleted operator '='
    :325:5: note: candidate function has been explicitly deleted
    

    Can someone tell me where the problem is? I have no idea^^^

    Thx & Goodbye!

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Please show the code you're using.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • B Offline
        B Offline
        buzz_lightzyear
        wrote on last edited by
        #3

        Here the content of the header:

        //program.h
        private:
        QFile gpxFile;
        
        public:
        QFile &getGpxFile() const;
        setGpxFile(const QFile &newGpxFile);
        

        ...and here the content of the .cpp

        const QFile &BikeTour::getGpxFile() const
        {
            return gpxFile;
        }
        
        void BikeTour::setGpxFile(const QFile &newGpxFile)
        {
            gpxFile = newGpxFile;  //Here is the problem. The IDE says: Overload resolution selected deleted operator '='
        }
        
        

        Thank you for your help!

        Christian EhrlicherC 1 Reply Last reply
        0
        • B buzz_lightzyear

          Here the content of the header:

          //program.h
          private:
          QFile gpxFile;
          
          public:
          QFile &getGpxFile() const;
          setGpxFile(const QFile &newGpxFile);
          

          ...and here the content of the .cpp

          const QFile &BikeTour::getGpxFile() const
          {
              return gpxFile;
          }
          
          void BikeTour::setGpxFile(const QFile &newGpxFile)
          {
              gpxFile = newGpxFile;  //Here is the problem. The IDE says: Overload resolution selected deleted operator '='
          }
          
          

          Thank you for your help!

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @buzz_lightzyear said in QFile - Problem with generated setter:

          QFile &getGpxFile() const;

          const QFile &BikeTour::getGpxFile() const

          These are two different functions.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          3
          • B Offline
            B Offline
            buzz_lightzyear
            wrote on last edited by
            #5

            ok... can you please tell me exactly where the problem is? I don't see it... otherwise I wouldn't ask here. :-)

            Christian EhrlicherC 1 Reply Last reply
            0
            • B buzz_lightzyear

              ok... can you please tell me exactly where the problem is? I don't see it... otherwise I wouldn't ask here. :-)

              Christian EhrlicherC Online
              Christian EhrlicherC Online
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @buzz_lightzyear said in QFile - Problem with generated setter:

              can you please tell me exactly where the problem is?

              Simply compare the return values

              QFile &

              reference

              const QFile &

              const reference

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              1 Reply Last reply
              1
              • C Offline
                C Offline
                ChrisW67
                wrote on last edited by ChrisW67
                #7

                Unless I missed something, this code assumes you can copy a QFile object.
                In QObject the copy constructor and assignment operator are deliberately disabled (i.e. deleted). QFile is ultimately a QObject.

                1 Reply Last reply
                3
                • B Offline
                  B Offline
                  buzz_lightzyear
                  wrote on last edited by
                  #8

                  Thank you! :-)

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    buzz_lightzyear
                    wrote on last edited by
                    #9

                    Ok... that was too early. I don't even know why the setter is not working. Can you please give me an example of a working setter for my example? I have checked the return values but I don't come to a resolution. It is not working :-(

                    Thx in advance!
                    buzzzzz

                    JonBJ 1 Reply Last reply
                    0
                    • B buzz_lightzyear

                      Ok... that was too early. I don't even know why the setter is not working. Can you please give me an example of a working setter for my example? I have checked the return values but I don't come to a resolution. It is not working :-(

                      Thx in advance!
                      buzzzzz

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

                      @buzz_lightzyear
                      QString, QDate and QImage are not QObjects and so can be copied and a setter can be written. QFile however inherits QObject. That means it cannot be copied. You won't be able to do a gpxFile = newGpxFile like for the others. Even though the IDE may let you try to write a setter for it you won't get it to work.

                      You might perhaps have a pointer to a QObject-derived class (e.g. QFile *) as a member variable with a setter, but that's another matter.

                      Even if it worked, what would you want to set/copy a QFile for?

                      1 Reply Last reply
                      1
                      • B Offline
                        B Offline
                        buzz_lightzyear
                        wrote on last edited by
                        #11

                        Ok thanks for your answer. The idea behind that is a simple bike-tour logger with a sqlite database in background. After a tour I want to enter the tourdata (eg. odometer...) to get a statistic over my tours over the year. And therefore I want also to upload the GPS generated tour as blob into the database. For that reason I thought a QFile is the best class for that because I don't want to edit the gpx file. But it seems to be hard. Do you have an example for another class?

                        Thx and goobye,
                        buzzzzz

                        M JonBJ 2 Replies Last reply
                        0
                        • B buzz_lightzyear

                          Ok thanks for your answer. The idea behind that is a simple bike-tour logger with a sqlite database in background. After a tour I want to enter the tourdata (eg. odometer...) to get a statistic over my tours over the year. And therefore I want also to upload the GPS generated tour as blob into the database. For that reason I thought a QFile is the best class for that because I don't want to edit the gpx file. But it seems to be hard. Do you have an example for another class?

                          Thx and goobye,
                          buzzzzz

                          M Offline
                          M Offline
                          mpergand
                          wrote on last edited by mpergand
                          #12

                          @buzz_lightzyear
                          Since you're talking about sqlite, the only information you need is the filepath of the database.
                          And then, just open and update that database when you needed to.

                          B 1 Reply Last reply
                          2
                          • M mpergand

                            @buzz_lightzyear
                            Since you're talking about sqlite, the only information you need is the filepath of the database.
                            And then, just open and update that database when you needed to.

                            B Offline
                            B Offline
                            buzz_lightzyear
                            wrote on last edited by
                            #13

                            @mpergand said in QFile - Problem with generated setter:

                            @buzz_lightzyear
                            Since you're talking about sqlite, the only information you need is the filepath of the database.
                            And then, just open and update that database when you needed to.

                            thx but I think this is not this what I need now. The database connection is already established.

                            Christian EhrlicherC 1 Reply Last reply
                            0
                            • B buzz_lightzyear

                              @mpergand said in QFile - Problem with generated setter:

                              @buzz_lightzyear
                              Since you're talking about sqlite, the only information you need is the filepath of the database.
                              And then, just open and update that database when you needed to.

                              thx but I think this is not this what I need now. The database connection is already established.

                              Christian EhrlicherC Online
                              Christian EhrlicherC Online
                              Christian Ehrlicher
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @buzz_lightzyear said in QFile - Problem with generated setter:

                              The database connection is already established.

                              So why do you need a QFile object for it then? If you open a sqlite database with Qt you don't need a QFile object at all.

                              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                              Visit the Qt Academy at https://academy.qt.io/catalog

                              1 Reply Last reply
                              0
                              • B buzz_lightzyear

                                Ok thanks for your answer. The idea behind that is a simple bike-tour logger with a sqlite database in background. After a tour I want to enter the tourdata (eg. odometer...) to get a statistic over my tours over the year. And therefore I want also to upload the GPS generated tour as blob into the database. For that reason I thought a QFile is the best class for that because I don't want to edit the gpx file. But it seems to be hard. Do you have an example for another class?

                                Thx and goobye,
                                buzzzzz

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

                                @buzz_lightzyear said in QFile - Problem with generated setter:

                                I want also to upload the GPS generated tour as blob into the database. For that reason I thought a QFile is the best class for that

                                • You can use a QFile for this if you wish, you just can't copy/assign via the setter you were trying. As I said earlier, a QFile * could be used in the pattern you are choosing.

                                • Or you could pass e.g. the file path around and use QFile when you need to read in the contents to send as a blob to the database.

                                B 1 Reply Last reply
                                0
                                • B Offline
                                  B Offline
                                  buzz_lightzyear
                                  wrote on last edited by
                                  #16

                                  So why do you need a QFile object for it then? If you open a sqlite database with Qt you don't need a QFile object at all.

                                  I need the QFile object for the gpx-file, not for the SQlite database. For that I have the QSqlDatabase class.

                                  Christian EhrlicherC 1 Reply Last reply
                                  0
                                  • JonBJ JonB

                                    @buzz_lightzyear said in QFile - Problem with generated setter:

                                    I want also to upload the GPS generated tour as blob into the database. For that reason I thought a QFile is the best class for that

                                    • You can use a QFile for this if you wish, you just can't copy/assign via the setter you were trying. As I said earlier, a QFile * could be used in the pattern you are choosing.

                                    • Or you could pass e.g. the file path around and use QFile when you need to read in the contents to send as a blob to the database.

                                    B Offline
                                    B Offline
                                    buzz_lightzyear
                                    wrote on last edited by
                                    #17

                                    @JonB said in QFile - Problem with generated setter:

                                    @buzz_lightzyear said in QFile - Problem with generated setter:

                                    I want also to upload the GPS generated tour as blob into the database. For that reason I thought a QFile is the best class for that

                                    • You can use a QFile for this if you wish, you just can't copy/assign via the setter you were trying. As I said earlier, a QFile * could be used in the pattern you are choosing.

                                    • Or you could pass e.g. the file path around and use QFile when you need to read in the contents to send as a blob to the database.

                                    ok thanks... then I will try it this way.

                                    1 Reply Last reply
                                    0
                                    • B buzz_lightzyear

                                      So why do you need a QFile object for it then? If you open a sqlite database with Qt you don't need a QFile object at all.

                                      I need the QFile object for the gpx-file, not for the SQlite database. For that I have the QSqlDatabase class.

                                      Christian EhrlicherC Online
                                      Christian EhrlicherC Online
                                      Christian Ehrlicher
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      @buzz_lightzyear said in QFile - Problem with generated setter:

                                      I need the QFile object for the gpx-file

                                      No you don't as @JonB already told you (several times iirc)

                                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                                      Visit the Qt Academy at https://academy.qt.io/catalog

                                      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