Results 1 to 9 of 9

Thread: Obtain const QImage from QByteArray

  1. #1
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Obtain const QImage from QByteArray

    What do you means for "trying to obtain a const QIMage from a QByteArray"?

    It depends to how QImage is stored in QByteArray.
    If you want to use a "standard" way read here
    A camel can go 14 days without drink,
    I can't!!!

  2. The following user says thank you to mcosta for this useful post:

    gorsanmo (26th April 2011)

  3. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Obtain const QImage from QByteArray

    What you have written will never work. socket->readAll() will only read and return what is available, which is unlikely to be an entire image. You need to keep reading each time you get a signal until you have received all the bytes and then attempt to turn it into an image. How you decide how many bytes are required is upto you, maybe you transmit it in the data, maybe it's fixed, that part is upto you.

  4. The following user says thank you to squidge for this useful post:

    gorsanmo (26th April 2011)

  5. #3
    Join Date
    Apr 2011
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Obtain const QImage from QByteArray

    Hello :
    Do you know where I can find any example of code for doing it ? Which method of QTCPSocket will I have to use ? Is the socket->readAll() not the correct method ?
    Could you answer me ?
    Thanks
    GOrka

  6. #4
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Obtain const QImage from QByteArray

    What you probably want is:
    from server:
    Qt Code:
    1. QDataStream stream(&arr, QIODevice::WriteOnly);
    2. stream.setVersion(QDataStream::Qt_4_7);
    3.  
    4. QImage image = ...;
    5. stream << image;
    To copy to clipboard, switch view to plain text mode 
    then in client:
    Qt Code:
    1. QDataStream stream(&some_socket, QIODevice::ReadOnly);
    2. stream.setVersion(QDataStream::Qt_4_7);
    3.  
    4. QImage image = ...;
    5. stream >> image;
    To copy to clipboard, switch view to plain text mode 
    The operators are in the documentation, >> and << for QImageHope this helps

  7. The following user says thank you to Fallen_ for this useful post:

    gorsanmo (26th April 2011)

  8. #5
    Join Date
    Apr 2011
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Obtain const QImage from QByteArray

    1.
    QDataStream stream(&some_socket, QIODevice::ReadOnly);
    2.
    stream.setVersion(QDataStream::Qt_4_7);
    3.

    4.
    QImage image = ...;
    5.
    stream >> image;


    What would be the code for QImage ( QIMage= ... )
    Thanks
    GOrka

  9. #6
    Join Date
    Aug 2010
    Posts
    58
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Obtain const QImage from QByteArray

    from the client should just be "QImage image;"

  10. The following user says thank you to Fallen_ for this useful post:

    gorsanmo (26th April 2011)

  11. #7
    Join Date
    Apr 2011
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Obtain const QImage from QByteArray

    when you use
    QDataStream stream(&some_socket, QIODevice::ReadOnly);
    stream.setVersion(QDataStream::Qt_4_7);

    QImage image = ...;
    stream >> image;
    Does it mean that all the stream is kept in the stream ?

    What does QImage image = ... mean ? DOes it mean that QImage image = new QImage ()?

  12. #8
    Join Date
    Apr 2011
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Obtain const QImage from QByteArray

    Hello :
    Do you need to use in your TCP Client any kind of SIGNAL -- SLOT ?
    For example , the one that I use here :

    QTCPSocket socket = new QTCPSocket(this);
    soket ->connectToHost("XXX","YYY");
    connect(soket,SIGNAL(readyRead()),this,SLOT(leer_c aracter()))

    Could you answer me as soon as possible ?
    Thanks
    gorsanmo


    Added after 42 minutes:


    As you have said , the code of the client is the following :


    then in client:
    QDataStream stream(&some_socket, QIODevice::ReadOnly);
    stream.setVersion(QDataStream::Qt_4_7);

    QImage image = ...;
    stream >> image;
    The operators are in the documentation, >> and << for QImageHope this helps

    1) Is it supponed that in QDataStream(&some_socket, QIODevice::ReadOnly) , &some_socket is a QByteArray obtained reading an especific socket ?
    For example

    soket = new QTcpSocket(this);
    soket->connectToHost("xxx","yyy");

    connect(soket,SIGNAL(readyRead()),this,SLOT(leerca racter()));





    leercaracter()
    {
    some_socket = soket->readall()
    QDataStream(&some_socket, QIODevice::ReadOnly)
    }
    Last edited by gorsanmo; 27th April 2011 at 00:47.

  13. #9
    Join Date
    Apr 2011
    Posts
    10
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Obtain const QImage from QByteArray

    Hello ,
    what would be the best way for obtaining an Image by reading bytes from a QTCPSocket ?
    Do you have any code example ?
    Thanks

Similar Threads

  1. Replies: 3
    Last Post: 18th November 2010, 17:52
  2. const char* QImage Format?
    By grabalon in forum Newbie
    Replies: 2
    Last Post: 13th May 2010, 00:44
  3. Streaming QImage (QByteArray, QDataStream, QBuffer)
    By knarz in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2009, 22:05
  4. Constructing QImage from QBytearray
    By dbrmik in forum Newbie
    Replies: 6
    Last Post: 16th December 2008, 15:00
  5. QImage to QByteArray
    By navi1084 in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 09:36

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.