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. [SOLVED]save a png file
Forum Updated to NodeBB v4.3 + New Features

[SOLVED]save a png file

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 7.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.
  • J Offline
    J Offline
    jk_mk
    wrote on last edited by
    #1

    Hello,

    In my application I create a png file and save it in a directory (named result.png). I want to get this image without using a dialog box from this directory and then save it in an other directory using a dialog box.How could this be done? I hope someone could help.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      a combination of "QFile :: copy":http://doc.qt.nokia.com/4.7/qfile.html#copy and "QFileDialog ":http://doc.qt.nokia.com/4.7/qfiledialog.html will do the trick.

      Vote the answer(s) that helped you to solve your issue(s)

      1 Reply Last reply
      0
      • L Offline
        L Offline
        loladiro
        wrote on last edited by
        #3

        So let me see if I got this correct. You create an Image and save it in some directory as result.png and then you want to copy it to another directory, while the user can choose the directory with a file dialog ("QFileDialog::getExistingDirectory":http://doc.qt.nokia.com/4.7/qfiledialog.html#getExistingDirectory). To copy, you can either use QFile::copy or just open one file, read it into a QByteArray (I would suggest to adjust the size of the read depending on memory and harddrive sector size) and write that back to a different file.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          jk_mk
          wrote on last edited by
          #4

          To copy an image from one directory to another should be something like the following code. But I want to copy two files for 3D images (.hdr, .img), which are located in the same directory. How I could copy these both two image files in an other directory by using the same QFileDialog for saving images?

          @void MainWindow::save()
          {

          QString newName = QFileDialog::getSaveFileName(
          this,
          tr("Save image"),
          QDir::currentPath(),
          tr("Image (*.img)") );

          QFile::copy("result.img",newName);

          }@

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kkrzewniak
            wrote on last edited by
            #5

            Wild guess:
            @void MainWindow::save()
            {

            QString newName = QFileDialog::getSaveFileName(
            this,
            tr("Save image"),
            QDir::currentPath(),
            tr("Image (*.img)") );

            QFile::copy("result.img",newName);
            newName.replace(".img",".hdr");
            QFile::copy("result.hdr",newName);
            }@

            Me, Grimlock, not "nice dino". ME BASH BRAINS!

            1 Reply Last reply
            0
            • J Offline
              J Offline
              jk_mk
              wrote on last edited by
              #6

              I have tried this and I get my results. But with this method I open a QFileDialog twice. Is there any method to do the same thing just using QFileDialog once?

              @QString newName_hdr = QFileDialog::getSaveFileName(
              this,
              tr("Save image"),
              QDir::currentPath(),
              tr("Image (*.hdr)") );

              QString newName_img = QFileDialog::getSaveFileName(
              this,
              tr("Save image"),
              QDir::currentPath(),
              tr("Image (*.img)") );

              QFile::copy("result.hdr",newName_hdr);
              QFile::copy("result.img",newName_img);@

              1 Reply Last reply
              0
              • J Offline
                J Offline
                jk_mk
                wrote on last edited by
                #7

                Thanks kkrzewniak,

                It was exactly what I was looking for. The problem is solved.

                1 Reply Last reply
                0

                • Login

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