2
29/8/2015 How to Store and Retrieve Image on SQLite/es Qt Wiki https://wiki.qt.io/How_to_Store_and_Retrieve_Image_on_SQLite/es 1/2 How to Store and Retrieve Image on SQLite/es From Qt Wiki < How to Store and Retrieve Image on SQLite This article may require cleanup to meet the Qt Wiki's quality standards. Reason: Autoimported from ExpressionEngine. Please improve this article (//wiki.qt.io/index.php? title=How_to_Store_and_Retrieve_Image_on_SQLite/es&action=edit) if you can. Remove the {{cleanup}} tag and add this page to Updated pages list after it's clean. Español English Como Guardar y Recuperar una Imagen o Archivo con SQLite Imágenes o cualquier tipo de archivos pueden ser guardados en un banco de datos. Aguí esta una manera de hacerlo siguiendo los siguientes pasos: 1. Cargar el archivo dentro de un QByteArray. 2. Guardar el QByteArray como un Binary Large Object (BLOB) en el banco de datos. Por ejemplo : QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) return; QByteArray byteArray = file.readAll(); QSqlQuery query; query.prepare("INSERT INTO imgtable (imgdata) VALUES (?)"); query.addBindValue(byteArray); query.exec(); Ahora, la imagen/archivo puede ser recuperada como cualquier otro tipo de dato QSqlQuery query("SELECT imgdata FROM imgtable"); query.next(); QByteArray array = query.value(0).toByteArray(); Creando un QPixmap desde un QByteArray : QPixmap pixmap; pixmap.loadFromData(array); Esta hecho. Ahora el pixmap puede ser usado en un QButton como un icono o en un QLabel, etc. Retrieved from "http://wiki.qt.io/index.php? title=How_to_Store_and_Retrieve_Image_on_SQLite/es&oldid=15157" Categories: Articles needing cleanup HowTo QtDevelopmentSpanish::General Snippets Spanish

How to Store and Retrieve Image on SQLite_es - Qt Wiki.pdf

  • Upload
    jaymonc

  • View
    17

  • Download
    4

Embed Size (px)

Citation preview

Page 1: How to Store and Retrieve Image on SQLite_es - Qt Wiki.pdf

29/8/2015 How to Store and Retrieve Image on SQLite/es ­ Qt Wiki

https://wiki.qt.io/How_to_Store_and_Retrieve_Image_on_SQLite/es 1/2

How to Store and Retrieve Image on SQLite/esFrom Qt Wiki< How to Store and Retrieve Image on SQLite

This article may require cleanup to meet the Qt Wiki's quality standards. Reason:Auto­imported from ExpressionEngine.Please improve this article (//wiki.qt.io/index.php?title=How_to_Store_and_Retrieve_Image_on_SQLite/es&action=edit) if you can. Remove the{{cleanup}} tag and add this page to Updated pages list after it's clean.

Español English

Como Guardar y Recuperar una Imagen oArchivo con SQLiteImágenes o cualquier tipo de archivos pueden ser guardados en un banco de datos. Aguí esta una manerade hacerlo siguiendo los siguientes pasos:

1. Cargar el archivo dentro de un QByteArray. 2. Guardar el QByteArray como un Binary Large Object(BLOB) en el banco de datos.

Por ejemplo :

 QFile file(fileName); if (!file.open(QIODevice::ReadOnly)) return; QByteArray byteArray = file.readAll(); QSqlQuery query; query.prepare("INSERT INTO imgtable (imgdata) VALUES (?)"); query.addBindValue(byteArray); query.exec();

Ahora, la imagen/archivo puede ser recuperada como cualquier otro tipo de dato

 QSqlQuery query("SELECT imgdata FROM imgtable"); query.next(); QByteArray array = query.value(0).toByteArray();

Creando un QPixmap desde un QByteArray :

 QPixmap pixmap; pixmap.loadFromData(array);

Esta hecho. Ahora el pixmap puede ser usado en un QButton como un icono o en un QLabel, etc.

Retrieved from "http://wiki.qt.io/index.php?title=How_to_Store_and_Retrieve_Image_on_SQLite/es&oldid=15157"Categories:  Articles needing cleanup HowTo QtDevelopmentSpanish::General Snippets Spanish

Page 2: How to Store and Retrieve Image on SQLite_es - Qt Wiki.pdf

29/8/2015 How to Store and Retrieve Image on SQLite/es ­ Qt Wiki

https://wiki.qt.io/How_to_Store_and_Retrieve_Image_on_SQLite/es 2/2

This page was last modified on 29 March 2015, at 15:35.This page has been accessed 413 times.