PDA

View Full Version : program close unexpectedly after adding QHttpMultiPart in my software



Mohammadhzp
18th January 2014, 17:14
Hello
I'm newbie,so sorry if my question is simple
I had some problem for uploading file through HTTP,finally I got the solution,here is a working example (http://paste.ofcode.org/4VQqLdMTTybPYL6HbBfcf2)
then I just change my code to work with QHttpMultiPart,when I was done,I run my program to see if everything is fine,but after adding a file to upload,my software close unexpectedly (no raising error,just crash)
here (http://paste.ofcode.org/34B4t8QWF9dFEaa9nSMrRMP) is a basic working example of my code
problem is in Uploader class,the upload method.
I can't understand what I'm doing wrong,can some one give me hint or a solution ?
I ask this question in qt forum but no answer,here is last place which can answer my question,so please help me on this one
Thanks

anda_skoa
18th January 2014, 18:57
You need to have a look at the stack trace from when the crash happens.

For example by running the program in a debugger or checking the backtrace on crash, etc.

Cheers,
_

Mohammadhzp
18th January 2014, 19:58
I did check the program in debugger but it gave me nothing and unfortunately I don't know how to check backtrace
edit: I'm downloading gdb (https://wiki.python.org/moin/DebuggingWithGdb) to debugging,I'll post result as soon as I get them

Added after 35 minutes:

try to debugging with gdb but just gdb gave me this
Segmentation fault (core dumped)
I have no idea what's this
after trying more I got this too
Program received signal SIGSEGV, Segmentation fault.
0xb5a9ed1b in ?? () from /usr/lib/i386-linux-gnu/libQtNetwork.so.4

ChrisW67
18th January 2014, 20:06
Gdb will not help you debug a Python program.

You can single step through a python program with pdb (http://docs.python.org/2/library/pdb.html) (the python debugger) ...do that until you find out where it dies.

Edit: you edited while i was writing. A segmentation fault typically indicates a null or invalid pointer in a C++ program. If python in crashing in this way with your program then I think it is likely to be a PyQt/pySide installation problem

Mohammadhzp
18th January 2014, 20:21
I tried gdb
I now which line this error occur,it's when I'm posting data
self._reply = self.parent().post(request, self._multiPart)
I'm now sure about it since got this error with gdb(I'll try pdb to see if I can get more information)
Program received signal SIGSEGV, Segmentation fault.
0xb5a9ed1b in ?? () from /usr/lib/i386-linux-gnu/libQtNetwork.so.4
but I can't understand why this is happening(other example in my first post is working,but mine example does not)

Added after 12 minutes:

I installed requirement with this command
sudo apt-get install build-essential python3-dev libqt4-dev
then I installed both SIB and PyQt which this command
python3.3 configure.py
make
sudo make install

did I installed it in wrong way ? if not,is possible that maybe a file is broken ?

edit : pdb give me nothing
Can someone please test my basic code (http://paste.ofcode.org/34B4t8QWF9dFEaa9nSMrRMP)of my program to see if it crash or not ?

edit2 : I think my PyQt is just fine,because this code (http://paste.ofcode.org/4VQqLdMTTybPYL6HbBfcf2) is working fine

ChrisW67
19th January 2014, 00:02
Ahh, there was a second link in your first post to your code.

Here is what I think is happening (I am not a Python master).

In handleAddUpload() you create a local variable QFile called stream. You pass that to uploader.upload() which stashes a reference to that QIODevice in your multipart message structures and calls post() to queue the transmission before returning. At this time the stream variable goes out of scope. When the Qt network code goes to send the actual POST and payload it tries to build the payload using the defunct stream. I suspect that causes the crash.

Mohammadhzp
19th January 2014, 00:31
Thanks Chris for reply




At this time the stream variable goes out of scope

I was suspected too but docs (http://pyqt.sourceforge.net/Docs/PyQt4/qiodevice.html) is saying that you need to call close(),because of that I thought it might not be the stream,unfortunately I'm new to python/PyQt,How do you think I can handle stream?(I mean if I need to change my code,how you suggest me to read data ?) ?:confused:
thanks

Mohammadhzp
19th January 2014, 16:57
I got the solution(the problem was I have no experience lol)
Basically the segfault happened because the qt objects were not deleted before the last reference to the instance of the upload was deleted
e.g in my code in uploader.upload() we assign data like this self._data = data and then in uploader.handleFinished() we delete self.__data like this : self._data.deleteLater() before self.__reply
hope it help some newbie like me
thanks guys for reply