PDA

View Full Version : "Segmentation Fault" for QHttp::setHost()



pritam
3rd March 2010, 05:15
Hi,

I'm trying a sample QT program available on trolltech webdoc [http://doc.trolltech.com/4.6/qhttp.html#details] to interface to HTTP.
But it's giving "SegFault" for QHttp::setHost(). Kindly help me to figure out the root cause and fix to resolve it.

Following is the code snippet that I've tried.
---------------------------------------------
QHttp m_pHttp = new QHttp();
void CHttpClient::execute()
{
QHttpRequestHeader header("GET", QUrl::toPercentEncoding("/index.html"));
header.setValue("Host", "qt.nokia.com");
m_pHttp->setHost("qt.nokia.com");
m_pHttp->request(header);
}

Call stack
----------------------------
0 QBasicAtomicInt::operator!= qbasicatomic.h 75 0x680ac32a
1 QList<QHttpRequest*>::detach qlist.h 122 0x680a669f
2 QList<QHttpRequest*>::append qlist.h 468 0x680a661b
3 QHttpPrivate::addRequest qhttp.cpp 2385 0x6801206e
4 QHttp::setHost qhttp.cpp 2037 0x680113a0
5 CHttpClient::execute CCommunicator.cpp 93 0x004078f3
...


Excerpt:qbasicatomic.h
----------------------------

inline bool operator!=(int value) const
{
return _q_value != value;
}


here, this = 0x0 => resultuing into seg fault
----------------------------

regards,:confused:
pritam

aamer4yu
3rd March 2010, 06:11
QHttp m_pHttp = new QHttp();
Is it same in code ? I guess you are missing the pointer. Still I wonder how its compiling
Also am not sure if the request header object should be in a bigger scope.

pritam
3rd March 2010, 07:18
Sorry for the confusion,
it's pointer only, i.e.


QHttp* m_pHttp = new QHttp();

It's data member of my CHttpClient class, for reference I kept it outside.