Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. decode from QPointF
Qt 6.11 is out! See what's new in the release blog

decode from QPointF

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Hollywood33
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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;
      

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      H 1 Reply Last reply
      2
      • Christian EhrlicherC Christian Ehrlicher

        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;
        
        H Offline
        H Offline
        Hollywood33
        wrote on last edited by
        #3

        @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();
        

        }

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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 with

          if (!file.open(QIODevice::ReadOnly))

          H 1 Reply Last reply
          3
          • mrjjM mrjj

            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 with

            if (!file.open(QIODevice::ReadOnly))

            H Offline
            H Offline
            Hollywood33
            wrote on last edited by
            #5

            @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();
            
            1 Reply Last reply
            0
            • VRoninV Offline
              VRoninV Offline
              VRonin
              wrote on last edited by
              #6

              http://doc.qt.io/qt-5/qimage.html#save

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              1 Reply Last reply
              4

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved