Results 1 to 6 of 6

Thread: How to send Image trough TCP/ip in Qt?

  1. #1
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to send Image trough TCP/ip in Qt?

    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 ??

    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?
    Can any one provide me example to do this ???

    Thanks in advance

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to send Image trough TCP/ip in Qt?

    Quote Originally Posted by qtlinuxnewbie View Post
    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 ??

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to send Image trough TCP/ip in Qt?

    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:
    Qt Code:
    1. QImage img = getMyImage();
    2. QTcpSocket *sock = getMySocket();
    3. img.save(sock);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Feb 2010
    Posts
    61
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to send Image trough TCP/ip in Qt?

    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

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to send Image trough TCP/ip in Qt?

    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.

  6. #6
    Join Date
    Feb 2010
    Posts
    3
    Qt products
    Qt4 Qt/Embedded Qt Jambi
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: How to send Image trough TCP/ip in Qt?

    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.

Similar Threads

  1. Replies: 6
    Last Post: 21st September 2009, 10:55
  2. Send a Image throw a QDataStream
    By gt.beta2 in forum Newbie
    Replies: 5
    Last Post: 20th March 2009, 23:07
  3. send signal from 1 gui to another gui
    By tho97 in forum Qt Programming
    Replies: 3
    Last Post: 5th December 2007, 21:21
  4. Send a key to process
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 9th July 2007, 17:37
  5. Replies: 3
    Last Post: 14th March 2007, 08:09

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.