QFile - Problem with generated setter
-
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!
-
Please show the code you're using.
-
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!
-
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!
@buzz_lightzyear said in QFile - Problem with generated setter:
QFile &getGpxFile() const;
const QFile &BikeTour::getGpxFile() const
These are two different functions.
-
ok... can you please tell me exactly where the problem is? I don't see it... otherwise I wouldn't ask here. :-)
-
ok... can you please tell me exactly where the problem is? I don't see it... otherwise I wouldn't ask here. :-)
@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
-
Thank you! :-)
-
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 -
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@buzz_lightzyear
QString
,QDate
andQImage
are notQObject
s and so can be copied and a setter can be written.QFile
however inheritsQObject
. That means it cannot be copied. You won't be able to do agpxFile = 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? -
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 -
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@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. -
@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.@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.
-
@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.
@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.
-
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@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, aQFile *
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.
-
-
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.
-
@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, aQFile *
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.
@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, aQFile *
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.
-
-
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.
@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)