Results 1 to 20 of 22

Thread: Segfault when retrieving info from QSettings

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Segfault when retrieving info from QSettings

    Do you need members in those classes? I personally create and destroy the settings objects when I need them.

    Qt Code:
    1. void C::m(p){
    2. QString v = s.value("xxx");
    3. //...
    4. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segfault when retrieving info from QSettings

    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...

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Segfault when retrieving info from QSettings

    Currently the number of those objects is a source of confusion And you'd have to sync() all the instances before every use.

  4. #4
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segfault when retrieving info from QSettings

    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!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Segfault when retrieving info from QSettings

    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.

  6. #6
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segfault when retrieving info from QSettings

    I tried that but I got the error. Again, I'm using this custom settings class because I need some of the members to modify the information before continuing. All the relevant code is above. I'm willing to do anything, as long as I don't need to create a QSettings object for each member.

    By the errors being different I meant in different parts of the code, ie in other members.


    Thanks!

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Segfault when retrieving info from QSettings

    So why don't you run the debugger and analize the backtrace the same way as before?

    I'd really suggest taking the singleton approach. You'll spend hours debugging the code and you could achieve the same result just less error prone by making your settings class a singleton with a static member returning the instance.

  8. #8
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segfault when retrieving info from QSettings

    Sorry.. what do you mean by singleton?

    Again, thanks for your help

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Segfault when retrieving info from QSettings


  10. The following user says thank you to wysota for this useful post:

    codeslicer (21st March 2008)

  11. #10
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segfault when retrieving info from QSettings

    Thanks, but how does that help me? I have found out that the segfault originates when accessing ANY member function of QSettings. So this isn't a problem reading from the actual physical source, but from accessing the actual QSettings object. I have used these types of pointers before, nothing bad happened though... I'll check my source again.

    Thanks!

  12. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Segfault when retrieving info from QSettings

    You have null pointers and the singleton will eliminate that. Take a look at this:

    Qt Code:
    1. class Settings : public QSettings {
    2. public:
    3. Settings *instance() {
    4. static Settings *m_instance = new Settings;
    5. return m_instance;
    6. }
    7. //..
    8. protected:
    9. Settings() : QSettings(qApp){}
    10. };
    11.  
    12. void someClass::someMethod(){
    13. int v = Settings::instance()->value("param", 7).toInt();
    14. }
    To copy to clipboard, switch view to plain text mode 

  13. The following user says thank you to wysota for this useful post:

    codeslicer (21st March 2008)

  14. #12
    Join Date
    Feb 2008
    Posts
    153
    Thanks
    40
    Thanked 8 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Talking

    Thanks for your help with the singleton approach, I will keep that in mind if I have to use it later, but I have located my problem.

    I was referring to my custom settings class which used a pointer to a QSettings object. I fixed this by just explicately defining it in my header file. The reason for the error was that when I was experimenting before I commented the #include settings.h line and that caused the problem.

    Thanks a lot for your help though, sorry for having you go through all that trouble

    Also, one final question - if I define an object in a header file, what is it's parent?
    Last edited by wysota; 21st March 2008 at 08:39. Reason: Posts merged

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.