The previous example uses the native QImage class from Qt, which contains functions that can access pixel data and manipulate it. It is also used to load an image file and extract its data through different decompression methods, depending on the format of the image. Once the data is extracted, you can do anything you want with it, such as display the image onscreen, manipulate its color information, resize the image, or compress it with another format and save it as a file.
We used QFileInfo to separate the filename from the extension so that we can amend the extension name with the new format selected by the user from the combo box. This way, we can save the newly-converted image in the same folder as the original image and automatically give it the same file name as well, except in a different format.
As long as you're trying to convert the image to a format supported by Qt, you just need to call QImage::save(). Internally, Qt will figure out the rest for you and output the image to the chosen format. In the QImage::save() function, there is a parameter that sets the image quality and another that sets the format. In this example, we just set both as the default values, which saves the image at the highest quality and lets Qt figure out the format by checking the extension stated in the output filename.