Unsolved Application Crash when i call my function
-
Hello everyone , i'm trying to get value from xml file using qt , so there is the xml file :
<favorites> <server> <ip>127.0.0.1:7777</ip> <nickname></nickname> <password></password> </server> <server> <ip>127.1.1.1:7777</ip> <nickname>bdfjhd</nickname> <password></password> </server> <server> <ip>125.1.1.1:5445</ip> <nickname>fdkgfhfhf</nickname> <password></password> </server> </favorites>
and this is my function :
QString FavFile::GetFavListServers() { QFile file("favlist.xml"); file.open(QIODevice::ReadOnly); QXmlStreamReader stream(&file); QString Ip; QString Name; QString Pass; try { while(stream.readNext() && !stream.isEndDocument()) { if(stream.name() == "server") { qDebug() << "server found"; while(stream.readNext() && !stream.isEndElement()) { if(stream.name() == "ip") { Ip = stream.readElementText(); } if(stream.name() == "nickname") { Name = stream.readElementText(); } if(stream.name() == "password") { Pass = stream.readElementText(); } } qDebug() << "IP: " + Ip; } } } catch(QException &ex) { qDebug() << "Bug In try"; } file.close(); }
The function work but app didn't responds ... there is some log :
output :
server found "IP: 127.0.0.1:7777" server found "IP: 127.1.1.1:7777" server found "IP: 125.1.1.1:5445" Le programme s'est terminé subitement . ---> crash
Debug :
Signal name : SIGSEGV Signal meaning : Segmentation fault
i think my loop didnt stop but i dont know why , thanks for help :)
-
Hi,
You should get a stack trace. That will help pinpoint the problem.
-
hi
with such short input u can also just single step it using debugger and see what go wrong. -
@Jaber Isn't the crash somewhere else in your program, not in FavFile::GetFavListServers()?
You should really just debug as suggested by others.One note: there is no need to concatenate string when using qDebug:
qDebug() << "IP:" << Ip;
-
while(stream.readNext() && !stream.isEndElement()) { if(stream.name() == "ip")
Here you take for granted that
stream.readNext()
returnedQXmlStreamReader::StartElement
which is not the case as it can be onQXmlStreamReader::Characters