Results 1 to 15 of 15

Thread: Segmentation fault regarding QString in Qt/linux

  1. #1
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Segmentation fault regarding QString in Qt/linux

    Hi all,

    I am getting segmentation fault error while running my Qt application.Following is the gdb- backtrace output.

    (gdb) backtrace
    #0 0xb64daf62 in QString:perator= () from /usr/share/qt4/lib/libQtCore.so.4
    #1 0xb80937ee in CCustomisationManager::dataDir (this=0x952ee88)
    at CustomisationManager.cpp:179
    #2 0x0807c9a3 in CUIFramework::loadPreferences (this=0x952ee88) at UIFramework.cpp:91
    #3 0x0807d197 in CUIFramework::start (this=0x952ee88) at UIFramework.cpp:75
    #4 0x0805d136 in main (argc=3, argv=0xbfed5424) at main.cpp:64

    In CCustomisationManager.cpp ,line 179

    Qt Code:
    1. CCustomisationManager::dataDir()
    2. {
    3. return m_dataDir;
    4. }
    To copy to clipboard, switch view to plain text mode 

    m_dataDir is declared as private in CCustomisationManager.h

    Qt Code:
    1. private:
    2.  
    3. QString m_dataDir;
    To copy to clipboard, switch view to plain text mode 

    In CUIFRamework.cpp ,line 91

    Qt Code:
    1. void CUIFramework::loadPreferences()
    2. {
    3. QString preferenceFilePath = CCustomisationManager::getInstance()->dataDir() + "\\SensoFind_Preferences.xml";
    4. }
    To copy to clipboard, switch view to plain text mode 

    In line 75,

    Qt Code:
    1. void CUIFramework::start()
    2. {
    3. loadPreferences();
    4. }
    To copy to clipboard, switch view to plain text mode 

    m_dataDir is getting initialised in Init() in CCustomisationManager.cpp

    Qt Code:
    1. void CCustomisationManager::Init()
    2. {
    3. m_DataDir = QDir::currentPath() + QDir::separator()+ "\\test.xml";
    4. }
    To copy to clipboard, switch view to plain text mode 

    I am not getting any idea on what is wrong,am left with no clue.....plz help me out in this regard...............

    Regards,
    Payal

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Segmentation fault regarding QString in Qt/linux

    What is the full signature of dataDir()? (= return type) and just as a node: if you use QDir::separator() (which is fine) don't add slashes and use separator() consequently.

    EDIT: try following workaround:
    Qt Code:
    1. QString tmp = CCustomisationManager::getInstance()->dataDir();
    2. QString preferenceFilePath = tmp + "\\SensoFind_Preferences.xml";
    To copy to clipboard, switch view to plain text mode 

    EDIT2: And is CCustomisationManager::Init() ever called?

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    m_dataDir != m_DataDir

    but that also should not be a problem.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  4. #4
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    Plz find some corrections to the code...

    void CCustomisationManager::Init()
    {

    m_DataDir = QDir::currentPath() + QDir::separator() + m_BrandData->getStringValue(PREF_GENERAL, "data_dir");
    }

    and dataDir() returns Qstring..

    I tried Keeping breakpoint on Init(),but while running,its not hitting..............

    Expecting a reply from you....

    Payal

  5. #5
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    I tried Keeping breakpoint on Init(),but while running,its not hitting..............
    ensure that u r in DEBUG MODE. setBuildConfiguration under Build menu.
    and press ctrl +4 and confirm ur qmake is in DEBUG mode. [ did u rem the previous post,in which i attached the screenshot of the configuration]
    if both are correct. Then clean the project. and rebuild again
    then breakpoint should work.

    pls put
    Qt Code:
    1. qDebug()<<QDir::currentPath() + QDir::separator() + m_BrandData->getStringValue(PREF_GENERAL, "data_dir");
    To copy to clipboard, switch view to plain text mode 

    to find the value in m_dataDir .

    pls ensure , its m_dataDir or m_DataDir

    hope it helps
    Bala

  6. #6
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    Thanks alot for your help..

    yaa......... The Init() was not getting called since one condition was not getting satisfied and the condition checks the QString value..............and it was resulting Segmentation fault.

    So now i am trying to find out the QString value...................

    Payal

  7. #7
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    hi...........

    Again segmentation fault error.........while trying to assign a QString to another Qstring .following is the gdb backtrace output.

    (gdb) bt
    #0 0xb63a1f6a in QString:perator= () from /usr/share/qt4/lib/libQtCore.so.4
    #1 0xb7f5a852 in CCustomisationManager::init (this=0x9701e10, brandName=
    {static null = {<No data fields>}, static shared_null = {ref = {_q_value = 25}, alloc = 0, size = 0, data = 0x808d79a, clean = 0, simpletext = 0, righttoleft = 0, asciiCache = 0, capacity = 0, reserved = 0, array = {0}}, static shared_empty = {ref = {_q_value = 1}, alloc = 0, size = 0, data = 0xb6543a6e, clean = 0, simpletext = 0, righttoleft = 0, asciiCache = 0, capacity = 0, reserved = 0, array = {0}}, d = 0xbfe9a214, static codecForCStrings = 0x0})
    at CustomisationManager.cpp:103
    #2 0x0807add6 in CUIFramework::executeCommandLineArgs (this=0x9701e10, argList=0x9701c98)
    at UIFramework.cpp:300

    line 103 in CustomisationManager.cpp

    void CCustomisationManager::init(QString brandName)
    {
    m_BrandName = brandName; // m_BrandName declared private in CCustomisationManager
    .....................
    }
    line 300 in UIFramework.cpp:

    CUIFramework::executeCommandLineArgs()
    {
    CCustomisationManager::getInstance()->init(brand);

    }

    am not getting any idea about why a simple QString assigment operation is causing Segmentation fault error?

    if somebody has any ideas ,plz share with me...........am stucked up with this issue..........

    Regards,
    Payal

  8. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Segmentation fault regarding QString in Qt/linux

    This way I think we can't help you further. So please create a minimal compilable example reproducing your problem.

  9. #9
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    CUIFramework::executeCommandLineArgs()
    {
    CCustomisationManager::getInstance()->init(brand);
    }
    brand? is QString? or what?

    what is the value of it?
    check the value by
    qDebug<<brand;
    does it properly initialized?

    check it out.
    Bala
    Last edited by BalaQT; 24th February 2010 at 14:55.

  10. #10
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    yaa.i checked the value of brand which is of QString..dat is initialised properly ......
    i am checking that value before assigning and while passing to init().

  11. #11
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    ine 103 in CustomisationManager.cpp

    void CCustomisationManager::init(QString brandName)
    {
    m_BrandName = brandName; // m_BrandName declared private in CCustomisationManager
    .....................
    }
    line 300 in UIFramework.cpp:

    CUIFramework::executeCommandLineArgs()
    {
    CCustomisationManager::getInstance()->init(brand);

    }

    show us some more code reg brand.
    declaration part , initialization

    Bala

  12. #12
    Join Date
    Feb 2010
    Posts
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    Iniitailisation part

    for (int index =0 :index<list.count();index++)
    {
    QString brand = list->at(index); list is of type QList<QString>*

    }

    and init(brand) is called

  13. #13
    Join Date
    Aug 2009
    Location
    coimbatore,India
    Posts
    314
    Thanks
    37
    Thanked 47 Times in 43 Posts
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    #1]
    for (int index =0 :index<list.count();index++)
    {
    QString brand = list->at(index); list is of type QList<QString>*

    }
    if u put brand inside for loop
    its focus will be lost when it comes out of the loop

    try

    Qt Code:
    1. QString brand;
    2. for (int index =0;index<list.count();index++)
    3. {
    4. brand = list->at(index);
    5. }
    To copy to clipboard, switch view to plain text mode 


    #2] post the declaration part of list;
    and how u adding the string item to the list. [post the code]

    #3] have u tried the following
    Qt Code:
    1. QString brand;
    2. for (int index =0;index<list.count();index++)
    3. {
    4. qDebug()<<list->at(index);
    5. brand = list->at(index);
    6. }
    To copy to clipboard, switch view to plain text mode 

    #4] when u r calling init(brand)?

    Bala
    Last edited by BalaQT; 25th February 2010 at 06:14.

  14. #14
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    Quote Originally Posted by payal View Post
    Iniitailisation part

    for (int index =0 :index<list.count();index++)
    {
    QString brand = list->at(index); list is of type QList<QString>*

    }




    and init(brand) is called
    brand will have only the last QString value ... u have to go for QStringList instead of QString and declare the scope outside as bala mentioned ..
    QStringList brand_list;
    for (int index =0 ;index<list.count();index++)
    {
    brand << list->at(index); list is of type QList<QString>*

    }
    "Behind every great fortune lies a crime" - Balzac

  15. #15
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Segmentation fault regarding QString in Qt/linux

    payal can you show us your exact code? or when you are shortening your code try to keep those parts to have any sense. This does not have any sense:
    Qt Code:
    1. for (int index =0 :index<list.count();index++)
    2. {
    3. QString brand = list->at(index); list is of type QList<QString>*
    4.  
    5. }
    To copy to clipboard, switch view to plain text mode 

    And my guess would be to check if your CCustomisationManager::getInstance() returns valid pointer.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

Similar Threads

  1. Segmentation fault when creating new QString
    By di_zou in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 18:07
  2. Segmentation fault
    By Schimanski in forum Qt Programming
    Replies: 20
    Last Post: 31st August 2009, 16:26
  3. Segmentation Fault?!
    By r07f1 in forum Newbie
    Replies: 2
    Last Post: 11th April 2008, 15:10
  4. segmentation fault insert QString in QCombobox
    By regix in forum Qt Programming
    Replies: 16
    Last Post: 8th August 2006, 08:46
  5. (Another) segmentation fault
    By Lebowski in forum Qt Programming
    Replies: 27
    Last Post: 6th April 2006, 06:33

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.