Results 1 to 7 of 7

Thread: Trouble loading UI (with images) from plugin (.so)

  1. #1
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Trouble loading UI (with images) from plugin (.so)

    Hi,

    I have a plugin that loads and shows a custom widget that displays an image (as a background for a QLabel) loaded from a resource file (resources.qrc). The problem I'm facing is that once the plugin is loaded, it shows the widget properly, but not the image. I tried putting "Q_INIT_RESOURCE( resources )" everywhere, but nothing happens. I have created many custom widgets that use qrc files to display images, but only directly within an app, which have worked just fine. This time is from a plugin, so there must be something I'm missing here. Any help?


    Qt Code:
    1. // TheInterface.h
    2. class TheInterface
    3. {
    4. ...
    5. }
    6. Q_DECLARE_INTERFACE(TheInterface,"com.system.subsystem.TheInterface/1.0");
    7.  
    8.  
    9.  
    10. // MyWidget.h
    11. class MyWidget : public QWidget, public Ui::MyWidget
    12. {
    13. Q_OBJECT
    14. ...
    15. }
    16.  
    17.  
    18.  
    19. // MyPlugin.h
    20. #include "TheInterface.h"
    21. class MyPlugin : public QOBject,
    22. public TheInterface
    23. {
    24. Q_OBJECT
    25. Q_INTERFACES(TheInterface)
    26.  
    27. ...
    28. };
    29.  
    30. // MyPlugin.cpp
    31. #include "MyPlugin.h"
    32. #include "MyWidget.h"
    33. MyPlugin::MyPlugin()
    34. {
    35. MyPlugin* w = new MyPlugin();
    36. w->show();
    37. }
    38.  
    39. Q_EXPORT_PLUGIN2(myplugin, MyPlugin)
    To copy to clipboard, switch view to plain text mode 

  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: Trouble loading UI (with images) from plugin (.so)

    You don't show us any code that attempts to use a resource or where the "everywhere" you tried putting "Q_INIT_RESOURCE( resources )" was. It helps if you cut and paste your actual code rather than re-keying it and introducing errors, e.g. "QOBject" or the MyPlugin constructor trying to allocate another copy of MyPlugin on the heap (kinda recursive isn't it?).

    I'm fairly sure the "Q_INIT_RESOURCE( resources )" should be in the MyPlugin constructor so that it executes when the plugin is loaded and before any factory method (assuming you have one) returns a MyWidget to the program.

  3. #3
    Join Date
    May 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble loading UI (with images) from plugin (.so)

    Thanks for your response.

    I'm sorry for the errors. You are right, but I'm not allowed to paste the whole code.

    In MyPlugin constructor, what I meant was:

    Qt Code:
    1. MyPlugin::MyPlugin()
    2. {
    3. MyWidget* w = new MyWidget();
    4. w->show();
    5. }
    To copy to clipboard, switch view to plain text mode 

    The resource is used from within the UI. My .pro file looks like this:

    Qt Code:
    1. TEMPLATE = lib
    2. CONFIG += plugin debug resources
    3. INCLUDEPATH += /path/to #TheInterface.h
    4.  
    5. HEADERS = MyPlugin.h \
    6. MyWidget.h
    7.  
    8. SOURCES = MyPlugin.cpp \
    9. MyWidget.cpp
    10.  
    11. DEPENDPATH += . resources
    12.  
    13. RESOURCES += resources/resources.qrc
    14.  
    15. FORMS = mywidget.ui
    16.  
    17. TARGET = myplugin
    To copy to clipboard, switch view to plain text mode 

    Also, within MyWidget.h, I'm properly doing
    Qt Code:
    1. #include "ui_mywidget.h"
    To copy to clipboard, switch view to plain text mode 

    I tried putting "Q_INIT_RESOURCE( resources )" in MyPlugin constructor, but no image is shown. I did the equivalent to the following:
    Qt Code:
    1. MyPlugin::MyPlugin()
    2. {
    3. Q_INIT_RESOURCE( resources );
    4. }
    To copy to clipboard, switch view to plain text mode 

    I did try to change "resources" for something buggy like "resourcesss" and at plugin loading time the error shown was:
    ... /path/to/my/libmyplugin.so: undefined symbol: _Z26qInitResources_resourcesssv

    Any other idea?

    Thanks

  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: Trouble loading UI (with images) from plugin (.so)

    The error means you don't have a resource file called "resources" linked into your library.
    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
    May 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble loading UI (with images) from plugin (.so)

    Thanks for your response, but, please, read again. I made that error happen on purpose by putting a buggy value. Instead of specifying "resources" I put "resourcesss", just to prove that "resources" is ok, and "resourcesss" is not. So, back to the main question:

    Why isn't an image (loaded from a resource file, resources.qrc) showing up in a widget that is loaded from a plugin?

    Thanks again.

  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: Trouble loading UI (with images) from plugin (.so)

    What's the type of the image?
    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
    May 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Trouble loading UI (with images) from plugin (.so)

    Problem solved.
    Thanks a lot for your responses.

    The problem was that the main application has already a qrc file with the same name (resources.qrc). The plugin, being loaded by the main app, has a different resources.qrc file, but because the main app had one already, it was not loading it. I changed the name of the resource file in the plugin, worked perfectly. Of course, I had to change the "Q_INIT_RESOURCE( resources );" to "Q_INIT_RESOURCE( new_resource_file_basename );". Also, it was enough to call this in the constructor of the MyWidget class. In other words, it does NOT need to be in the constructor of the plugin (MyPlugin::MyPlugin()). It makes sense, since the MyWidget is the one using the resource file, not the plugin.

    Thanks again for your support.

    -Daniel

Similar Threads

  1. Loading images from url in qt 4
    By shalini in forum Newbie
    Replies: 4
    Last Post: 15th September 2011, 16:21
  2. dll loading trouble
    By ldynasa in forum Qt Programming
    Replies: 3
    Last Post: 23rd February 2011, 15:05
  3. Slow loading images
    By abbapatris in forum Qt Programming
    Replies: 10
    Last Post: 5th March 2008, 15:52
  4. Trouble placing background images
    By WinchellChung in forum Newbie
    Replies: 2
    Last Post: 5th July 2007, 14:33
  5. Loading images in QTextBrowser
    By nisha0609 in forum Qt Programming
    Replies: 1
    Last Post: 3rd January 2007, 09:44

Tags for this Thread

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.