PDA

View Full Version : Segmentation fault regarding QString in Qt/linux



payal
23rd February 2010, 11:57
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::operator= () 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


CCustomisationManager::dataDir()
{
return m_dataDir;
}

m_dataDir is declared as private in CCustomisationManager.h


private:

QString m_dataDir;

In CUIFRamework.cpp ,line 91


void CUIFramework::loadPreferences()
{
QString preferenceFilePath = CCustomisationManager::getInstance()->dataDir() + "\\SensoFind_Preferences.xml";
}

In line 75,


void CUIFramework::start()
{
loadPreferences();
}

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


void CCustomisationManager::Init()
{
m_DataDir = QDir::currentPath() + QDir::separator()+ "\\test.xml";
}

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

Regards,
Payal

Lykurg
23rd February 2010, 13:26
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:
QString tmp = CCustomisationManager::getInstance()->dataDir();
QString preferenceFilePath = tmp + "\\SensoFind_Preferences.xml";

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

high_flyer
23rd February 2010, 13:27
m_dataDir != m_DataDir

but that also should not be a problem.

payal
24th February 2010, 04:54
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

BalaQT
24th February 2010, 06:32
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

qDebug()<<QDir::currentPath() + QDir::separator() + m_BrandData->getStringValue(PREF_GENERAL, "data_dir");

to find the value in m_dataDir .

pls ensure , its m_dataDir or m_DataDir

hope it helps
Bala

payal
24th February 2010, 06:50
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

payal
24th February 2010, 10:33
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::operator= () 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

Lykurg
24th February 2010, 11:53
This way I think we can't help you further. So please create a minimal compilable example reproducing your problem.

BalaQT
24th February 2010, 14:29
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

payal
25th February 2010, 04:49
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().

BalaQT
25th February 2010, 05:03
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

payal
25th February 2010, 05:44
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

BalaQT
25th February 2010, 06:02
#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



QString brand;
for (int index =0;index<list.count();index++)
{
brand = list->at(index);
}


#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


QString brand;
for (int index =0;index<list.count();index++)
{
qDebug()<<list->at(index);
brand = list->at(index);
}

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

Bala

wagmare
25th February 2010, 06:44
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>*

}

faldzip
25th February 2010, 07:42
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:


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

}


And my guess would be to check if your CCustomisationManager::getInstance() returns valid pointer.