PDA

View Full Version : Deploying Qt Application on Windows - Load JPG Images Problem



Aleksandar
15th July 2011, 17:04
Hi folks,

Basic Description:
I made Qt application that loads BMP, JPG, PNG... files. It works perfectly on PC with installed QtSDK.

Problem:
When I deploy it to PC without installed QtSDK (by deploying I mean only copying exe file and some dll files to the same folder) then problems occure.
The application can still load BMP and PNG files, but can not load JPG files.

Code:


void Widget::OpenImage()
{
QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"), QDir::currentPath());

if (!fileName.isEmpty())
{
QPixmap pixmapP(fileName); //HERE IS THE PROBLEM !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!

if (pixmapP.isNull())
{
QMessageBox::information(this, tr("Image Viewer"), tr("Cannot load %1.").arg(fileName));
return;
}

m_pixmapImage = pixmapP;
}
}


Question:
Can anyone give me some directions how to deploy Qt application that loads JPG files?
I visited http://doc.qt.nokia.com/latest/deployment-windows.html but it wasn't helpful for me (configure command not recognized in Qt command prompt).

Notes:
I have attached my complete source code and print screens that show the structure of my "deploy" folder

stampede
15th July 2011, 17:42
qjpeg4.dll should be placed in plugins/imageformats directory (watch for typos).

viulskiez
15th July 2011, 17:49
And don't forget to call QApplication::addLibraryPath() or QApplication::setLibraryPaths().

Aleksandar
16th July 2011, 19:36
Thanks stampede,
qjpeg4.dll was in the folder: debug\plugins\imageformats
and in the folder debug\imageformats (just in case)
You were right that I should watch for typos (there was an error). I fixed it but it still didn't work.

stampede
16th July 2011, 19:42
Ok, and what about viulskiez hint:

And don't forget to call QApplication::addLibraryPath() or QApplication::setLibraryPaths().
?

Aleksandar
16th July 2011, 19:46
Thanks viulskiez,
I added to code what You said, but it's still acting the same way!
Perhaps I should add some code to .pro file:



QT += core gui

TARGET = TestLoadPicture
TEMPLATE = app


SOURCES += main.cpp\
widget.cpp

HEADERS += widget.h

FORMS += widget.ui


Hi stampede,
I was writing response to viulskiez while You were writing new message.
I added QApplication::addLibraryPath() or QApplication::setLibraryPaths() to main function. Still the same.

stampede
16th July 2011, 21:03
Can you show the code ? Calling qApp->addLibraryPath("<path>/plugins"); should be enough.

ChrisW67
16th July 2011, 22:42
In your first screen shot the "plugins" directory is actually named "plagins".

You should dispense with the "plugins" directory and place all the image format plugins in a single "imageformats" subdirectory in the directory holding your application. The application should just find the plugins without any extra configuration or code on your part (this is how I deploy my app). Also make sure the plugins are from the exact same version of Qt that your application is built with (and not the plugins from the Qt Creator directory by mistake for example).

Aleksandar
19th July 2011, 12:19
Problem solved! Thank You all!

stampede, I'm showing You the code You asked for:


#include <QtGui/QApplication>
#include "widget.h"


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
a.addLibraryPath(":/plugins/imageformats");

Widget w;
w.show();

return a.exec();
}



ChrisW67, I noticed typing error "plagins" instead of plugins the first time stampede adviced me to "watch for typos". That was not the problem. But, You were right that I should put imageformats folder directly into folder that contains *.exe file. You were also right that I should check the source of imageformats .dll files! When I did these two things the problem was solved!

In case anybody face similar problem, here is advice:
NEVER COPY imageformats dll files from this folder:
c:\QtSDK\QtCreator\bin\imageformats\

ALWAYS COPY imageformats dll files from this folder: c:\QtSDK\Desktop\Qt\4.7.3\mingw\plugins\imageforma ts\



Thank You all again, You were a great help to me!

roestzwiee
24th October 2012, 12:18
Hello to all of you.

I have a similar problem, i'm using QWebWidget, that doensn't display the images. The last post form Aleksandar said to use the imageformat *.dlls from "c:\QtSDK\Desktop\Qt\4.7.3\mingw\plugins\imageforma ts\"

The problem i have with this statement, is, that i do not have that folder within the mingw directory. All solutions i have are stored in:

"C:\Qt\2010.05\qt\src\plugins" (but there is only the source and no *.dll files)

"C:\Qt\2010.05\qt\plugins"

"C:\Qt\2010.05\bin"

At the moment i use the third version in the bin directory. I tried both *.dll containing folders without success.
I'm using Windows7 with QT 4.7.0 on development pc and WindowsXP in VM for testing.

... fixed had to use... "C:\Qt\2010.05\qt\plugins" and had writing error

ChrisW67
24th October 2012, 22:39
To clarify this for the next person with a Me Too post...

The point of Aleksandar's post is that the SDK contains two sets of Qt components:

The set deployed with the pre-built Qt Creator in QtSDK\bin.
The Qt libraries, their may be several sets, that your application is built with and uses to run itself.

You want to deploy the libraries and plugins from the Qt libraries used to build your application, not those shipped to support Qt Creator.

Gokulnathvc
25th October 2012, 13:15
Go for static build instead copying all the dlls.

1. Install QtSDK (2009.05)

2. Open your mkspecswin32-g++qmake.conf file (located in C:\Qt\2009.05\qt\mkspecs\win32-g++\qmake.conf) in an editor like notepad.

3. Find the line that starts with "QMAKE_LFLAGS = -enable-stdcall-fixup..." and ddd the phrase "-static" (without quotes) after the "=" sign and before the "-enable..." phrase, so it looks like:
QMAKE_LFLAGS = -static -enable-stdcall...

4. Save and close this file.

5. Set your environment variables. Right-click Computer >> Properties >> Advanced System Settings >> Click the "Environment Variables..." button.

6. Under "User variables," make sure QTDIR is set to your Qt path (C:\Qt\2009.05\qt). Make sure QMAKESPEC is set to win32-g++.

7. Under "System variables," edit the one called "Path." Add a semicolon ( ; ) to the end, and add the following:
C:\Qt\2009.05\mingw\lib;C:\Qt\2009.05\mingw\bin;C: \Qt\2009.05\qt\bin

8. When finished, relog or reboot.

9. Open a command prompt.

10. Change to your Qt directory by entering: cd C:\Qt\2009.05\qt

11. Enter the following: configure -static -no-phonon -no-phonon-backend -release -no-exceptions

12. When it asks which edition you want to use, enter "o" for open source.

13. When it asks you to accept the terms of the license, enter "y" for yes. This will take around maybe 10 minutes to complete.

14. When that finishes, enter the following: mingw32-make sub-src (or) nmake sub-src

15. Go out to dinner, this will take a while (took between 1-2 hours for me).

16. When this finishes, open your project in the Qt Creator.

17. Double-click the project (.pro) file to open it in edit mode.

18. Add the following line: CONFIG += static

19. qmake Hello.pro
nmake release (or) mingw32-make release

20. Navigate to your release directory and voila! Your standalone executable should be there.