Results 1 to 6 of 6

Thread: sending QImage over serial port

  1. #1
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Question sending QImage over serial port

    Hello, i am trying to send a QImage file over serial port; but i couldn't manage it..
    There is no data sent in serial port monitor, when i send the file "avatar.gif"..(with send function of Qextserialport)
    Am i missing something...

    here is my code:

    Qt Code:
    1. QByteArray bytes;
    2.  
    3. QImage picture(80, 80,QImage::Format_RGB32);
    4.  
    5. QImageReader reader("C:/Documents and Settings/pc/MyDocuments/Visual Studio 2005/Projects/videocapture3/avatar.gif");
    6.  
    7. reader.read(&picture);
    8.  
    9. picture.loadFromData(bytes);
    10.  
    11. sp->send(bytes.size(),bytes.data());
    To copy to clipboard, switch view to plain text mode 
    Last edited by jpn; 16th January 2008 at 21:37. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: sending QImage over serial port

    Where do you fill "bytes" with data?

  3. #3
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Question Re: sending QImage over serial port

    Ok.. I havent used QImage or QImagereader before; and perhaps I misunderstand them...

    Hello, i am trying to send a QImage file over serial port; but i couldn't manage it..
    There is no data sent in serial port monitor, when i send the file "avatar.gif"..(with send function of Qextserialport)
    Am i missing something...

    What i understand is that:

    Qt Code:
    1. QByteArray bytes;// a bytes array formed
    2.  
    3. QImage picture(80, 80,QImage::Format_RGB32); // a picture object formed
    4.  
    5. QImageReader reader("C:/Documents and Settings/pc/MyDocuments/Visual Studio 2005/Projects/videocapture3/avatar.gif"); //avatar.gif is read into "reader"
    6.  
    7. reader.read(&picture); // reads the image from reade into picture..
    8.  
    9. picture.loadFromData(bytes); // bytes are filled here
    10.  
    11. sp->send(bytes.size(),bytes.data());// bytes are sent here
    To copy to clipboard, switch view to plain text mode 


    is that wrong?
    Last edited by jpn; 16th January 2008 at 21:37. Reason: missing [code] tags

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: sending QImage over serial port

    Quote Originally Posted by yagabey View Post
    picture.loadFromData(bytes); // bytes are filled here
    On the contrary, you load data from bytes into picture. You can access image data using QImage::bits().

    What format do you need to send that image in?

  5. #5
    Join Date
    Dec 2007
    Location
    London
    Posts
    206
    Thanks
    40
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android

    Default Re: sending QImage over serial port

    I need te send it as it is.. I wont change the format while sending..
    I checked QImage::bits; it returns a uchar pointer. How to fill the bytes with that?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: sending QImage over serial port

    Quote Originally Posted by yagabey View Post
    I need te send it as it is.. I wont change the format while sending..
    Then you don't need QImage, but QFile::readAll().

    Quote Originally Posted by yagabey View Post
    I checked QImage::bits; it returns a uchar pointer. How to fill the bytes with that?
    Using proper QByteArray constructor.

Similar Threads

  1. serial port communiction
    By jagadish in forum Qt Programming
    Replies: 4
    Last Post: 7th July 2007, 12:04
  2. How to write bytes read from serial port to a QFile
    By shamik in forum Qt Programming
    Replies: 19
    Last Post: 25th June 2007, 14:12
  3. First attempt to display serial port data on GUI
    By ShaChris23 in forum Newbie
    Replies: 12
    Last Post: 4th May 2007, 09:14
  4. qt network performance
    By criss in forum Qt Programming
    Replies: 16
    Last Post: 24th July 2006, 09:23
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.