Image is not show that load from sqlite database
Hi!
Photo are stored in a SQLite Database (from other application). Now I load data from database and want to load image in my label.
When I debug it, QByteArray is ok. But QPixmap is invalid. How can I fix it?
Thanks
.h file
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QSqlDatabase>
#include <QSqlQuery>
namespace Ui {
class MainWindow;
}
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
.cpp file
Code:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QPixmap>
#include <QSqlError>
#include <QBuffer>
MainWindow
::MainWindow(QWidget *parent
) : ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_pushButton_clicked()
{
myDb.setDatabaseName("D:/ArtistPhoto.db3");
if (!myDb.open()) {
qDebug() << " not open";
}
else {
qDebug() << " opened";
query
= new QSqlQuery ("SELECT Data FROM Artist WHERE NOT data IS NULL",myDb
);
if(query->first()) {
QByteArray outByteArray
= query
->value
("Data").
toByteArray();
outPixmap.loadFromData( outByteArray );
if(outPixmap.loadFromData(outByteArray,"PNG")) ui->label->setPixmap(outPixmap);
}
myDb.close();
}
}
Project source code and database file
http://bit.ly/2F1FNmd
Re: Image is not show that load from sqlite database
Quote:
When I debug it, QByteArray is ok. But QPixmap is invalid.
What do you mean by 'ok'?
What does your QByteArray return for isNull() or isEmpty()?
1 Attachment(s)
Re: Image is not show that load from sqlite database
ok means
qDebug() << outByteArray.isEmpty() << outByteArray.isNull();
false false
Attachment 12745Attachment 12745