Results 1 to 7 of 7

Thread: QImageWriter fails for JPG in dll, but works fine in exe

  1. #1
    Join Date
    Nov 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default QImageWriter fails for JPG in dll, but works fine in exe

    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.

    Qt Code:
    1. QImage image((const uchar*)(buffer), 640, 480, QImage::Format_RGB888);
    2. QBuffer outBuffer;
    3. ok = outBuffer.open(QIODevice::ReadWrite);
    4. qDebug() << "outBuffer.open " << ok;
    5. QImageWriter imgWriter(&outBuffer, "JPG");
    6. bool writeSuccess = imgWriter.write(image);
    7. if (!writeSuccess)
    8. {
    9. qDebug() << "write img failed because " << imgWriter.errorString();
    10. }
    To copy to clipboard, switch view to plain text mode 

    The result of this statement
    Qt Code:
    1. qDebug() << QImageWriter::supportedImageFormats();
    To copy to clipboard, switch view to plain text mode 
    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImageWriter fails for JPG in dll, but works fine in exe

    Do you construct a QApplication object in your dll? Without an application object plugins are not loaded.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QImageWriter fails for JPG in dll, but works fine in exe

    Quote Originally Posted by wysota View Post
    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?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImageWriter fails for JPG in dll, but works fine in exe

    I think it will be easier for you to create the application object and not use it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QImageWriter fails for JPG in dll, but works fine in exe

    Quote Originally Posted by wysota View Post
    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?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QImageWriter fails for JPG in dll, but works fine in exe

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Nov 2014
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QImageWriter fails for JPG in dll, but works fine in exe

    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

Similar Threads

  1. Replies: 15
    Last Post: 8th June 2013, 06:15
  2. Casted QGraphicsItem from qml file Won't works fine!
    By alizadeh91 in forum Qt Programming
    Replies: 4
    Last Post: 27th February 2012, 08:54
  3. Replies: 1
    Last Post: 31st December 2010, 16:35
  4. Replies: 3
    Last Post: 11th December 2009, 17:13
  5. update() works fine sometime but not everytime..!!
    By salmanmanekia in forum Qt Programming
    Replies: 19
    Last Post: 22nd August 2008, 09:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.