Solved Can you explain me this code?
-
@thippu In this case you need to check what setSettingsObject does to know whether it is a bug or not. Can you show its content?
Actually, as long as setSettingsObject does not store a pointer to settings there will not be any error. Most probably they just assign it to an instance variable, in which case it is copied (assignment/copy operator). -
@thippu said in Can you explain me this code?:
QSettings settings(new QSettings("filename path and filename",QSettings::IniFormat));
yeah, this is really poor. Since
QSettings
is aQObject
it compiles as it uses this constructor but the object allocated in the heap is unused and leaked.
Whoever wrote that code should undergo dire punishment -
@VRonin Oh, somehow I missed that "new" :-)
-
@jsulm said in Can you explain me this code?:
In this case you need to check what setSettingsObject does to know whether it is a bug or not. Can you show its content?
It was from the example "Settings editor", I'm studying the mechanism of it.
-
-
@thippu said in Can you explain me this code?:
example "Settings editor"
Oh, if this is from official Qt example than you should file a bug as this is a bad example then.
-
@jsulm said in Can you explain me this code?:
Oh, somehow I missed that "new" :-)
Really, you are the author?. :-)
-
-
@VRonin said in Can you explain me this code?:
Whoever wrote that code should undergo dire punishment
Well, should be possible. It's been written here
http://doc.qt.io/qt-5/qtwidgets-tools-settingseditor-mainwindow-cpp.html
should be in the docu change log right :)
-
@jsulm oh, yeah true I did edit once.
-
@thippu said in Can you explain me this code?:
It was from the example "Settings editor", I'm studying the mechanism of it.
The example is correct:
typedef QSharedPointer<QSettings> SettingsPtr;
and thenSettingsPtr settings(new QSettings(locationDialog->format(), locationDialog->scope(), locationDialog->organization(), locationDialog->application()));
or
SettingsPtr settings(new QSettings(fileName, QSettings::IniFormat));
The problem is you took the liberty of replacing a shared pointer with a stack object
-
@VRonin you are right, sorry, I thought that time It would not matter.