PDA

View Full Version : How to send Image trough TCP/ip in Qt?



qtlinuxnewbie
19th April 2010, 06:07
Hi,
I need to send the image from client to a server.
i am using Qt and sockets to do the task.

My Issue is : i want to send the Image to Client? how can i do that ?? :confused:

After googling i found, by converting the Image into string it can be possible .
so how do i convert the image into string in QT?:confused:
Can any one provide me example to do this ???

Thanks in advance :)

yogeshgokul
19th April 2010, 06:41
Hi,
I need to send the image from client to a server.
i am using Qt and sockets to do the task.

My Issue is : i want to send the Image to Client? how can i do that ?? :confused:

After googling i found, by converting the Image into string it can be possible .
Can any one provide me example to do this ???

Thanks in advance :)


Qts TCP classes are capable of transmitting image data. i.e. Binary data. You need to use QDataStream alongwith TCP classes. No one can give you any example as only you have your client and server.
Instead of jumping on Google direct, read Qts great docs first. And please note that converting Image data into QString is not required at all and could lead to further issues like data corruption.

wysota
19th April 2010, 16:49
To make you see yelling for an example without knowing what you are doing doesn't provide any benefits, here is the example of sending an image through a network socket:

QImage img = getMyImage();
QTcpSocket *sock = getMySocket();
img.save(sock);

qtlinuxnewbie
20th April 2010, 08:29
First of all i was not clear to u all.

i was using the traditional C socket calls in my QT(like socket,connect,send etc.,)
now i want to transfer the image using send .
my question was how to send this image (convert it to data to send );

any way i worked for that: Now, is it correct way ?
QImage img=QImage("/root/Desktop/IMG_0497.JPG");
QBuffer buffer;
QImageWriter writer(&buffer, "PNG");
writer.write(img);
QByteArray data;
data.append( buffer.data() );
--------------------------------------
@@@@Qtlinuxnewbie
:
yelling for an example without knowing what you are doing doesn't provide any benefits,
i was asking for examples so that i can learn for them . not just for copying as it is, without understanding.

Thnk u

wysota
20th April 2010, 11:57
You don't have to "convert" anything. Just send the data into the socket according to the protocol you are using. Qt has nothing to do here if you are using BSD sockets directly.

srf.hidayat
27th April 2010, 04:21
Hey Guy,
If you would like to learn something new especially in programming, Firstly, Try to read appropriate programming ebook related to what do you want to do. According to your case, first you have to read C++ GUI Programming with QT-4 ebook especially in page 329(Networking) and The Art of Building Qt Application, page 337. Try to do the examples and then read the code line by line carefully till you understand what the code to do and don't forget to read Qt Assistent too that making you more familiar with Qt ... after that try to change the code to fit with what do you want to do...if you've got stuck after you try write the code and you can not solve your problem yet..you can go to qt forum find the answer.
That the better way and the right way to learn something new in programming. There is no shortcut to learn something new.