View Full Version : http trouble again, segfaults when no internet

17th January 2006, 01:26
Hello, hopefully someone can help me out, and show me where I am making a mistake. I have attached a simple application that I am using to test two classes, Image and Document. Although in this example, it isn't totally representative of how classes are used, the http part and functionality is very much similar to how it is in real code. As well the API is somewhat similar to the real code, ie. Its one-time use classes that delete themselves upon finishing the job. The Image class is used to download an image from a web server. Document is used to get a html or xml, or any other type of document from a web server. You supply a url in the line edit, and press 1 of the two buttons. Get Image button gets the image, and then displays it in the top. Get Document button gets the document and puts it in the text edit in the bottom. The 2 http functionalities in the 2 classes are almost identical. The test works fine, except that it crashes when there is no internet connection. For example if I phisically remove the cable from my cable modem, and try to run this, it crashes. I am not sure exactly where the problem is. backtrace doesn't seem to provide much useful info, at least not to me. And I am not sure what else to try. Any ideas are welcome.


17th January 2006, 02:35
Try to debug the application and see where it crashes.

17th January 2006, 14:12
backtrace doesn't seem to provide much useful info
Could you post it here?

18th January 2006, 05:07
It seems like you're deleting some wrong pointer. But I'm just guessing. I haven't tried your code without connection yet, and haven't looked the code deeply neither but, maybe you should take a closer look at Image::httpDone(bool) slot where you're deleting objects.
Anyways, I agrre with Wysota, you should run your app with gdb and see where it crashes.


18th January 2006, 12:15

I tested on a Linux Debian, and here is the backtrace from gdb:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1220528448 (LWP 8604)]
0xb79b009d in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
(gdb) where
#0 0xb79b009d in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
#1 0xb79b0a2c in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
#2 0xb7a4e171 in QHttp::stateChanged () from /usr/lib/libQtNetwork_debug.so.4
#3 0xb7a4e22a in QHttpPrivate::setState () from /usr/lib/libQtNetwork_debug.so.4
#4 0xb7a4edfd in QHttpPrivate::closeConn () from /usr/lib/libQtNetwork_debug.so.4
#5 0xb7a56f68 in QHttpPrivate::slotError () from /usr/lib/libQtNetwork_debug.so.4
#6 0xb7a592a9 in QHttp::qt_metacall () from /usr/lib/libQtNetwork_debug.so.4
#7 0xb79b05b1 in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
#8 0xb79b0a2c in QMetaObject::activate () from /usr/lib/libQtCore_debug.so.4
#9 0xb7a68e94 in QAbstractSocket::error () from /usr/lib/libQtNetwork_debug.so.4
#10 0xb7a6b244 in QAbstractSocketPrivate::startConnecting () from /usr/lib/libQtNetwork_debug.so.4
#11 0xb7a6c859 in QAbstractSocket::qt_metacall () from /usr/lib/libQtNetwork_debug.so.4
#12 0xb7a770f2 in QTcpSocket::qt_metacall () from /usr/lib/libQtNetwork_debug.so.4
#13 0xb79af815 in QObject::event () from /usr/lib/libQtCore_debug.so.4
#14 0xb7b4d8b4 in QApplicationPrivate::notify_helper () from /usr/lib/libQtGui_debug.so.4
#15 0xb7b4e8c9 in QApplication::notify () from /usr/lib/libQtGui_debug.so.4
#16 0xb79a444d in QCoreApplication::sendPostedEvents () from /usr/lib/libQtCore_debug.so.4
#17 0xb7bb5711 in QEventDispatcherX11::processEvents () from /usr/lib/libQtGui_debug.so.4
#18 0xb79a1a24 in QEventLoop::processEvents () from /usr/lib/libQtCore_debug.so.4
#19 0xb79a1c76 in QEventLoop::exec () from /usr/lib/libQtCore_debug.so.4
#20 0xb79a4611 in QCoreApplication::exec () from /usr/lib/libQtCore_debug.so.4
#21 0xb7b4d5d7 in QApplication::exec () from /usr/lib/libQtGui_debug.so.4
#22 0x0804d0a3 in main (argc=1, argv=0xbfee1394) at imgtestdialog.cpp:216

That doesn't help a lot...


18th January 2006, 14:53
I think that the problem is with:
delete http;
http = 0;It looks like you delete it while there are still some unprocessed events. Since you call Image::deleteLater(), you could omit those two lines.

18th January 2006, 21:25
Sorry, i was sick with the flu or cold yesturday so haven't been using the computer. Anyway it looks like you guys solved the problem for me. Indeed if I comment out the delete http lines the code works fine. Kinda weird, didn't really think that could be the problem. Should have tried that maybe before posting I guess. thanks all.