Results 1 to 8 of 8

Thread: Retrieve QByteArray in .png from SQL database

  1. #1
    Join Date
    May 2016
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Post Retrieve QByteArray in .png from SQL database

    hello

    I have stored image in arraybyte in database and I am also able to run a query to retrieve arraybyte in QPixmap and displaying on QLable.

    I want to retrieve the same arraybyte from database but this time I have to store that file in automatic generated folder (Any name) with the format of PNG.

    What classes I can use to generate folder for storing my image file ?

    How to save the QPixmap in any folder or directory ?
    Qt Code:
    1. QPixmap::save()
    To copy to clipboard, switch view to plain text mode 
    just gives boolean value...but does it save file in a specific location?

    Looking for your guidance..

    Thanks in advance...

  2. #2
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieve QByteArray in .png from SQL database

    Simply use correct variant of method QPixmap::save.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Retrieve QByteArray in .png from SQL database

    Which format do you get the date in when you query the database?

    If it is PNG already you could just write the data directly into a file.

    If you need to decode it first, e.g. if it is saved in a different format in the database, then use QImage for loading/saving if you don't need to display it.
    (saves two conversions between QImage and QPixmap)

    Cheers,
    _

  4. #4
    Join Date
    May 2016
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Post Re: Retrieve QByteArray in .png from SQL database

    my image data is in bytes only. I am trying to save byte data using QPixmap::save in specific directory but I am not getting any png file in that specific folder.


    Added after 8 minutes:


    code for saving byte image in specific folder.
    Qt Code:
    1. QPixmap pix ("C:/Folder");
    2. QByteArray bytes = dataFromDatabase; //It is a byteArray data
    3. QBuffer buf(&bytes);
    4. buf.open(QIODevice::WriteOnly);
    5. pix.save(&buf, "PNG");
    To copy to clipboard, switch view to plain text mode 

    I used this code to save png file in folder but after running this code I am not getting any file in that folder.
    Last edited by sam123; 12th July 2016 at 09:47.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Retrieve QByteArray in .png from SQL database

    Quote Originally Posted by sam123 View Post
    my image data is in bytes only
    You mean like 32-bit ARGB or similar?

    Quote Originally Posted by sam123 View Post
    I used this code to save png file in folder but after running this code I am not getting any file in that folder.
    If you want to save to a png file, why do you write into the buffer?

    Cheers,
    _

  6. #6
    Join Date
    May 2016
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Retrieve QByteArray in .png from SQL database

    yes its similar, what would be the correct method to save png in specific folder. Could you please suggest me.

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Retrieve QByteArray in .png from SQL database

    Either use QFile instead of the buffer or just use the save() overload that takes a filename.

    Cheers,
    _

    P.S.: as I said before, if you don't need to display the image use QImage instead of forcing two QImage<->QPixmap conversions

  8. #8
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,536
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Retrieve QByteArray in .png from SQL database

    From line 1 of code : You try to work with QPixmap from file Folder in main directory of disk C:. Is this what You want ? I don't think so.

Similar Threads

  1. Retrieve of the data from the database..?
    By gunturrohith in forum Qt Programming
    Replies: 2
    Last Post: 24th April 2015, 11:10
  2. Replies: 2
    Last Post: 8th March 2014, 15:12
  3. Sql query to retrieve database table data
    By Cyrebo in forum Qt Programming
    Replies: 9
    Last Post: 30th March 2013, 18:20
  4. Replies: 2
    Last Post: 14th September 2009, 08:38
  5. Replies: 2
    Last Post: 14th September 2009, 08:31

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.