Hi, i'm currently loading images from a sqlite3 blob-field using this code:
Qt Code:
  1. void ImageViewer::loadImage ( int pic )
  2. {
  3. QSqlQuery query ( QSqlDatabase::database() );
  4. query.prepare ( "SELECT data FROM img_images WHERE id = :id" );
  5. query.bindValue ( ":id", img_list[pic] );
  6. query.exec();
  7. if ( query.next() )
  8. {
  9. return QImage::fromData ( query.value ( 0 ).toByteArray() ) );
  10. }
  11. else
  12. {
  13. return QImage();
  14. }
  15. }
To copy to clipboard, switch view to plain text mode 
Now i found some examples in one of my Qt-Books:
Qt Code:
  1. QImage ImageCollection::getImage( int id )
  2. {
  3. QSqlQuery qrx;
  4. qry.prepare ( "SELECT data FROM images WHERE id = :id" );
  5. qry.bindValue ( ":id", id );
  6. if ( !qry.exec() ) qFatal ( "Failed to get image" );
  7. if ( !qry.next() ) qFatal ( "Failed to get image id" );
  8. QByteArray array = qry.value ( 0 ).toByteArray();
  9. QBuffer buffer ( &array );
  10. buffer.open ( QIODevice::ReadOnly );
  11. QImageReader reader ( &buffer, "PNG" );
  12. QImage image = reader.read();
  13. return image;
  14. }
To copy to clipboard, switch view to plain text mode 
Which code is better, if i know that i only have one image format in the database and why? which one is the fastest?
Using Qt4.4b1, 4.4rc1 is compiling atm. System is Debian Sid.
C167