You have a null pointer which you are trying to dereference in line 104 of src/settings.cpp. Looks like you didn't initialize your settings object.
You have a null pointer which you are trying to dereference in line 104 of src/settings.cpp. Looks like you didn't initialize your settings object.
Initialize? Is this what you mean:
Qt Code:
}To copy to clipboard, switch view to plain text mode
I did this in my constructor.
I declared it in my header file too..
Qt Code:
private: //Internal QSettings declaration QSettings* internalAppSettings;To copy to clipboard, switch view to plain text mode
Could this be because the value doesn't exist? For example it has never been set before and it's returning null, but in that case wouldn't it return the string "default"? Or like the message said, are there multiple sources?
Symbol this is a variable with complex or multiple locations (DWARF2), length 4. (gdb)
I'm stumped![]()
This creates a local variable called internalAppSettings that gets destroyed immediately when the constructor returns. Your member variable is left uninitialized. Try this instead:
Qt Code:
}To copy to clipboard, switch view to plain text mode
Or better yet simply don't declare "internalAppSettings" as a pointer but instead as a regular object and then leave the constructor empty.
codeslicer (16th March 2008)
Thanks! I didn't know that the variable gets deleted.
Sorry for the delay, I thought it would work, but both of the solutions still return segfaults, with different errors...
Creating a QSettings object for each of the members solves the problem, but I think that's unneccesary. So... any help? I did a google search and noticed this happened in QDevelop to someone...
Just in case, attached is the relevant code:
main.cpp
Qt Code:
int main(int argc, char ** argv) { ... ... return app.exec(); }To copy to clipboard, switch view to plain text mode
settings.cpp
Qt Code:
#include <QtCore> #include "settings.h" } ... return internalAppSettings->value("main/info", "default").toString(); }To copy to clipboard, switch view to plain text mode
settings.h
Qt Code:
#ifndef SETTINGS_H #define SETTINGS_H #include <QWidget> #include <QSettings> { Q_OBJECT public: ... ... private: //Internal QSettings declaration QSettings *internalAppSettings; }; #endifTo copy to clipboard, switch view to plain text mode
Personally I don't see anything wrong with this... Yet I still get a segfault:
Qt Code:
Symbol this is a variable with complex or multiple locations (DWARF2), length 4.To copy to clipboard, switch view to plain text mode
This is really weirdAny hints?
Last edited by codeslicer; 18th March 2008 at 01:10. Reason: spelling error
**BUMP**
Any ideas?
Do you need members in those classes? I personally create and destroy the settings objects when I need them.
Eh.. well my application needs to access QSettings pretty often... creating all those QSettings would be a waste of space and a source of confusion...
Currently the number of those objects is a source of confusionAnd you'd have to sync() all the instances before every use.
Look, all I want to do is creat my own custom settings object, with members corresponding to different values. Later in my app, instead of declaring QSettings every time I need to use it, I could just create my settings object and just use settings.setValueOfSomething.
This is helpful because in some of my members I have the function process the input/output before returning/writing to disk.
Back on track, is this segfault preventable? Thanks!
Why don't you have a single settings object then which you will either pass as a pointer to every component that is to use it or make it a singleton? Your problems would instantly go away.
If you want me to help you with the current bad design, you have to at least tell me what the errors are, not only that they are different from previous ones.
Bookmarks