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. Saving an image in a file (SOLVED)
Forum Updated to NodeBB v4.3 + New Features

Saving an image in a file (SOLVED)

Scheduled Pinned Locked Moved General and Desktop
9 Posts 3 Posters 2.4k 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.
  • T Offline
    T Offline
    thescouse
    wrote on last edited by
    #1

    Hello everyone.
    I am new to Qt and hence am trying to learn it through working with documented examples.
    Currently I am working om the Image viewer example.
    I wanted to add a Save function alongwith the Open function already given...Here is what I have done:


    void ImageViewer::save()
    {QString fileName=QFileDialog::getSaveFileName(this,tr("Save File"),QDir::currentPath());
    QPixmap pixmap(*imageLabel->pixmap());
    QFile f(fileName);
    f.open(QIODevice::WriteOnly);
    pixmap.save();
    f.close();
    }

    But the program produces the following error on compilation:
    "no matching for call to QPixmap::save(QFile&, const char[4])"
    before I added the code fragment that actually accepted the image to save...the program sequence worked fine and it also saved an empty image in the desired location.
    So can anyone help me out here as in what would be the required coding for the same.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      The functions signature doesnot matches as that of yours.
      As the compile output says you need to pass filename and the format.
      See "QPixmap::save(const QString & fileName, const char * format = 0, int quality = -1)":http://qt-project.org/doc/qt-5.0/qtgui/qpixmap.html#save for more details.

      157

      1 Reply Last reply
      0
      • T Offline
        T Offline
        thescouse
        wrote on last edited by
        #3

        Okay, I now changed the coding according to what you said...here it is:
        void ImageViewer::savef()
        {
        QString fileName=QFileDialog::getSaveFileName(this,tr("Save File"),QDir::currentPath());
        QPixmap pixmap(*imageLabel->pixmap());
        QFile f(fileName);
        f.open(QIODevice::WriteOnly);
        pixmap.save(filename,"JPG");
        f.close();
        }
        Now the error says filename was not declared in this scope. What is the problem now? I think I have declared it above in the function.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          thescouse
          wrote on last edited by
          #4

          Sorry, my mistake...the coding is just fine...please don't worry to reply. Thanks a lot for your help...;)

          1 Reply Last reply
          0
          • p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

            Well just to remind, if you think that this thread is solved then mark it by editing the title and prepend [solved] ;)

            157

            1 Reply Last reply
            0
            • T Offline
              T Offline
              thescouse
              wrote on last edited by
              #6

              OK! (y)

              1 Reply Last reply
              0
              • L Offline
                L Offline
                lingyun9833
                wrote on last edited by
                #7

                Hello, Ijust want to tell you that, don't need : QFile f(fileName); f.open(QIODevice::WriteOnly);f.close();

                As a tree, I have my own posture.

                1 Reply Last reply
                0
                • p3c0P Offline
                  p3c0P Offline
                  p3c0
                  Moderators
                  wrote on last edited by
                  #8

                  Yes ofcourse it was not needed.

                  157

                  1 Reply Last reply
                  0
                  • T Offline
                    T Offline
                    thescouse
                    wrote on last edited by
                    #9

                    yea I see that. thanks ;)

                    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