Qt- unable to save jpeg files

2020-03-04 07:11发布

I am trying to save images in Qt. I am able to save all the formats except jpeg. I have the following libraries under the plugins/imageformats folder.

libqgif.so, libqjpeg.so.

Do I have to place them in a different folder to make this work? Is there any new libraries that I have to install to make this work. I work on linux platform and my application is supported on all linux platforms. So do I have to install separate libraries for each platform?

Thanks,

标签: qt
4条回答
等我变得足够好
2楼-- · 2020-03-04 07:23

You might find what the problem is by:

  • Setting the environment variable QT_DEBUG_PLUGINS to 1 before running your application.
    It will print the plugin loading attempts/successes/failures on the console.

  • Using a QImageWriter to get a more explicit error message than with just QImage::save or QPixmap::save :

    QImageWriter writer("/tmp/test.jpg");
    if(!writer.write(pixmap.toImage()))
    {
        qDebug() << writer.errorString();
    }
    
查看更多
欢心
3楼-- · 2020-03-04 07:23

Try adding the following line to your main:

QApplication::addLibraryPath( <path to directory containing libjpeg.so> );
查看更多
地球回转人心会变
4楼-- · 2020-03-04 07:26

Check if the linking in the .so files are proper.

查看更多
▲ chillily
5楼-- · 2020-03-04 07:43

Under windows the qjpeg4.dll must in a imageformats directory under the application's directory by default.

查看更多
登录 后发表回答