[Qt-interest] QImage fail to load jpg file after linking with qt in static lib way.

Malyushytsky, Alex alex at wai.com
Tue Dec 30 00:25:37 CET 2008


Using static QT has its own restrictions , disadvantages and require code modification to support some features.
Look in the documentation for Static Plugins

"Plugins can be linked statically against your application. If you build the static version of Qt, this is the only option for including Qt's predefined plugins.


To link statically against those plugins, you need to use the Q_IMPORT_PLUGIN<qtplugin.html#Q_IMPORT_PLUGIN>() macro in your application and you need to add the required plugins to your build using QTPLUGIN. For example, in your main.cpp:

 #include <QApplication>

 #include <QtPlugin>

 Q_IMPORT_PLUGIN(qjpeg)

 Q_IMPORT_PLUGIN(qgif)

 Q_IMPORT_PLUGIN(qkrcodecs)

 int main(int argc, char *argv[])

 {

     QApplication app(argc, argv);

     ...

     return app.exec();

 }

In the .pro file for your application, you need the following entry:

 QTPLUGIN     += qjpeg \

                 qgif \
                 qkrcodecs"

Alex

________________________________
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of James Yan
Sent: Friday, December 19, 2008 3:52 AM
To: qt-interest at trolltech.com
Subject: [Qt-interest] QImage fail to load jpg file after linking with qt in static lib way.

hey all,

i'm using qt at win32/msvc2005 express, my source code using QImage:

QImage img;
if(!img.load("c:/test.jpg"))
{
   printf("fail to load jpg file.\n");
}
else
{
   printf("success to load jpg file.\n");
}

the source code works well UNTIL i link my app with qt in statilc lib way, the result always be :    printf("fail to load jpg file.\n");
after debug in i found it fail at those qt code lines:

bool QImageReader::read(QImage *image)
...
    if (!d->handler && !d->initHandler())  // return false with this "if"
        return false;
...

any suggestion for me? thanks.


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

"This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you."

"Please consider our environment before printing this email."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081229/d1597dda/attachment.html 


More information about the Qt-interest-old mailing list