Unsolved decode from QPointF
-
Hi! I have this code:
QDataStream stream (&file);
stream. setVersion(QDataStream::Qt_4_2);
stream << QPointF(30, 30) << QImage("/Users/Desktop/scan.jpg");
if(stream.status() != QDataStream::Ok)
{
qDebug() << "Error";
}It creates some .bin file.
What is the code to create original .jpg file out of the .bin file? -
The same as you did but the other way round:
QDataStream stream (&file); stream.setVersion(QDataStream::Qt_4_2); QPointF p; QImage img; stream >> p; stream >> img;
-
@Christian-Ehrlicher I don't know why, it creates empty .jpg file:
void MainWindow::on_pushButton_2_clicked()
{
QString file_name = QFileDialog::getSaveFileName(this, "Save a file", "Qdir::homePath()");
QFile file(file_name);
if(file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QDataStream stream (&file);
stream.setVersion(QDataStream::Qt_4_2);
QPointF p;
QImage img;
stream >> p;
stream >> img;qDebug() << "Error"; } file.close();
}
-
Hi
You open the file as writeONLY. Dont u mean readOnly ?
Also you flag it as text file, but its a binary files so try withif (!file.open(QIODevice::ReadOnly))
-
@mrjj
I changed. Now it reads binary data. How to save it to .jpg?QString file_name = QFileDialog::getOpenFileName(this, "Save a file", "Qdir::homePath()");
QFile file(file_name);
if (!file.open(QIODevice::ReadOnly))
{
QDataStream stream (&file);
stream.setVersion(QDataStream::Qt_4_2);
QPointF p;
QImage img;
stream >> p;
stream >> img;qDebug() << "Error"; } file.close();
-