PDA

View Full Version : QImageWriter fails for JPG in dll, but works fine in exe



thoutekier
12th November 2014, 10:04
I'm having some difficulties saving an image as jpg.
When I run the following code in an application, everything works fine. However, the exact same code in a dll-function that gets called by an application, fails.


QImage image((const uchar*)(buffer), 640, 480, QImage::Format_RGB888);
QBuffer outBuffer;
ok = outBuffer.open(QIODevice::ReadWrite);
qDebug() << "outBuffer.open " << ok;
QImageWriter imgWriter(&outBuffer, "JPG");
bool writeSuccess = imgWriter.write(image);
if (!writeSuccess)
{
qDebug() << "write img failed because " << imgWriter.errorString();
}


The result of this statement

qDebug() << QImageWriter::supportedImageFormats();
in the app is

("bmp", "jpeg", "jpg", "pbm", "pgm","png", "ppm", "xbm", "xpm")
The output of the same statement inside the dll-code is

("bmp", "pbm", "pgm", "png", "ppm", "xbm", "xpm")

This is how it is deployed:
/test.exe (works fine)
/test2.exe (calls test.dll, doens't work)
/test.dll
/imageformats/qjpeg.dll

I'm using QT 5.2.1 msvc2012_64_opengl

Why don't I have jpg-support inside my dll, while I do have it in my application?

wysota
12th November 2014, 10:14
Do you construct a QApplication object in your dll? Without an application object plugins are not loaded.

thoutekier
12th November 2014, 10:23
Do you construct a QApplication object in your dll? Without an application object plugins are not loaded.

Thank you for your reply!
No, there is no QApplicationin the dll.
Is that necessary? I don't want a QApplicationin this particular dll. Is there any way I can load this plugin manually by configuration?

wysota
12th November 2014, 10:48
I think it will be easier for you to create the application object and not use it.

thoutekier
12th November 2014, 11:24
I think it will be easier for you to create the application object and not use it.

No it isn't.
The dll I want to use QImageWriter in is a native windows dll. I cannot have a qEventloop in there. It would interfere with the windows threads that are running in there. I just want to use some basic QT utilityclasses such as Qimage and qimagewriter without having a complete qapplication.
Is QPluginLoader somehing I could use?

wysota
12th November 2014, 12:08
You don't need to start the event loop. The application object simply needs to exist. Plugins are loaded by the constructor, as far as I remember.

thoutekier
17th November 2014, 14:57
Thanks for the input, but I had problems including a QCoreApplication inside my dll.
I succeeded by manually and dynamically loading the qjpeg.dll using QPluginLoader