Results 1 to 10 of 10

Thread: Exe not displaying images when compiled statically

  1. #1
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Exe not displaying images when compiled statically

    Hello,
    I have built a gui, using some jpegs for background images(set using pixmap property in Qt creator). It run fine in the Qt creator. But, when i tried to execute the exe(i have copied all the missing dll's it asked for), it seems to work fine but does not display the images. I looked through lots of similar posts & here is what i have tried so far.

    a)
    I have configured it statically
    configure -static -qt-libjpeg
    nmake

    b)
    I have tried to add images using resource editor, instead of loading them directly from a folder.
    <!DOCTYPE RCC><RCC version="1.0">
    <qresource>
    <file>images/begin1.jpg</file>
    <file>images/emerg.jpg</file>
    </qresource>
    </RCC>
    i have placed my jpegs in the 'images' folder(which i copied into the folder where my exe & qrc is located). I have also created an 'imageformat' folder which has the 'qjpeg4.dll' file

    c) i have edited my pro file

    CONFIG += static
    RESOURCES = interface.qrc

    & my mainwindow.cpp -> Q_INIT_RESOURCE(interface);

    d)
    I took a detour & tried using Qt plugins, but i had a link error. So i gave up on that.


    As, far as using the jpegs in my program, here is an example:

    this->ui->label_begin->show(); (label_begin's pixmap property loads begin1.jpg)


    Can you please point out the error i'm making? Thanks in Advance. If i hadn't given you enough information, do let me know as of what else you might need.


    Prem.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Exe not displaying images when compiled statically

    You have to ship the JPEG image format plugin, and probably others, with your application. If you are dynamically linking then they can simply be dropped in the correct place near your executable. If you are using a static Qt then the plugins must be built-in.

  3. #3
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Exe not displaying images when compiled statically

    Thanks for the quick reply. I tried to do it dynamically. when i tried to add the plugin, I get link errors

    in main.cpp
    #include <QtPlugin>
    Q_IMPORT_PLUGIN(qjpeg)

    in the .pro file
    QTPLUGIN += qjpeg
    (for some reason the word 'QTPLUGIN' doesn't appear in purple colour)

    i get the link error:
    main.obj:-1: error: LNK2019: unresolved external symbol "class QObject * __cdecl qt_plugin_instance_qjpeg(void)" (?qt_plugin_instance_qjpeg@@YAPAVQObject@@XZ) referenced in function "public: __thiscall StaticqjpegPluginInstance::StaticqjpegPluginInstan ce(void)" (??0StaticqjpegPluginInstance@@QAE@XZ)

    What more should i add?

    Thank You.

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

    Default Re: Exe not displaying images when compiled statically

    Quote Originally Posted by premroxx View Post
    I tried to do it dynamically.
    No, you didn't. The code posted suggests you are trying to use static plugins. The question is whether you have static plugins built in the first place.
    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
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Exe not displaying images when compiled statically

    When building statically you may need to explicit load the .qrc resource file using the Q_INIT_RESOURCE macro:

    Qt Code:
    1. Q_INIT_RESOURCE(Backgrounds);
    To copy to clipboard, switch view to plain text mode 

    This should be done in the main.cpp file before the QApplication is constructed, if I'm not mistaken.

    By the way: This was my first post, so I really hope it helps
    Plan everything. Document everything. Version control everything. Test everything. Deny everything.

  6. #6
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Exe not displaying images when compiled statically

    question is whether you have static plugins built in the first place
    This is what i have done so far.

    .pro
    CONFIG += static
    QTPLUGIN += qjpeg

    main.cpp
    #include <QtPlugin>
    Q_IMPORT_PLUGIN(qjpeg)

    I am getting an link(LINK2019) error. I also notice that the word 'QTPLUGIN' isn't showing up in a violet color like the other QT commands do? I have a imageformats folder(next to my .exe) with libqjpeg.a in it. What else am i doing wrong?

  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Exe not displaying images when compiled statically

    What is the error? My crystal ball is out of action...

  8. #8
    Join Date
    Aug 2011
    Posts
    42
    Thanks
    10
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Exe not displaying images when compiled statically

    main.obj:-1: error: LNK2019: unresolved external symbol "class QObject * __cdecl qt_plugin_instance_qjpeg(void)" (?qt_plugin_instance_qjpeg@@YAPAVQObject@@XZ) referenced in function "public: __thiscall StaticqjpegPluginInstance::StaticqjpegPluginInstan ce(void)" (??0StaticqjpegPluginInstance@@QAE@XZ)

    debug\interface.exe:-1: error: LNK1120: 1 unresolved externals

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

    Default Re: Exe not displaying images when compiled statically

    Forget the imageformats folder, it's only for dynamic plugins. The static plugins need to be available at compile time where the linker can find them.
    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.


  10. #10
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Exe not displaying images when compiled statically

    Have you built Qt statically?
    You need to build your application with a static version of Qt, not just configure your project for a static build. If you have built both Qt and your application statically you should not need any Qt related dll's. In any event, when using qrc files you do not need to deploy the image files after compilation, they will be built inn to your executable.

    From the error message it looks like the linker can't find the static version of the qjpeg library, indicating either a faulty path or that you don't have the qjpeg static library. Static files will most likely be .a files if you are using the MinGW compiler, and .lib if you are using msvc.

    If all you want is for your images to show in the application, perhaps the dynamic approach is the better one, using qrc resource files. If you need to deploy your application as a part of your job, then static build may be the way to go, however you do need a commercial Qt license to deploy static Qt applications.
    Plan everything. Document everything. Version control everything. Test everything. Deny everything.

Similar Threads

  1. Replies: 0
    Last Post: 25th July 2011, 14:47
  2. Qt 4.7.0 statically compiled and Qt Creator
    By Suppaman in forum Installation and Deployment
    Replies: 6
    Last Post: 12th October 2010, 12:47
  3. Statically compiled Qt 4.1.4 and mySql
    By Djony in forum Installation and Deployment
    Replies: 1
    Last Post: 26th January 2007, 07:13
  4. Replies: 3
    Last Post: 26th July 2006, 13:23
  5. Qt is compiled statically, now what ?
    By probine in forum Qt Programming
    Replies: 1
    Last Post: 30th May 2006, 12:46

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
  •  
Qt is a trademark of The Qt Company.