How dynamic plugins work with resources?
Two of my plugins are very similar. Exactly I started them from same code. Each of them creates object of class inheriting QGraphicsItem. This class draws picture from PNG file attached to resource. Then each plugin sends item pointer to main application which adds it to common QGraphicsScene. This all works except one unexpected effect.
In both plugins names of PNG files are the same. I expected that each plugin will get picture from it's own resource. Pictures are different - each plugin is assembled from it's own project tree (of course resource files are different too). But after graphics scene drew for first time - I saw 2 equally pictures. Actually 2nd plugin got picture from 1st plugin resource. Or from main application if resources were taken by main app.
I just removed 1st plugin from application directory. Then started app with only 2nd plugin - I saw proper picture from 2nd plugin's resource. Why I did not see it after both plugins were loaded?
What is wrong here? Are resources from plugins exported to main app in some way? Or mistake is somewhere else (this is just another day of 14 hours working time)?
Of course I can give different names to pictures and force item constructor use these names. But this is not so good. Plugins can be created by different people and file names can mix again later.
You compile resources into the code. Once you introduce the same name twice one of them is will win and be the visible one. I think it is undefined which one that is (not sure though).
Just put the resources into separate folders (e.g. using the plugin name). We do the same in Qt Creator by the way.
bq. You compile resources into the code.
but the code is different DLLs! the code is different! first DLL loads and it creates 1st item with picture, then second DLL loads and creates it's own item with picture... DLLs do not share code (except Qt-libraries) then where pictures interfere?
bq. Just put the resources into separate folders (e.g. using the plugin name).
you mean separate folders inside resource file aka prefixes, do you? looks like different prefixes will be enough
but I must give future plugin developers clean guide how to create plugins. My plugins can be identified only by some signature inside them. This signature cannot be used as prefix or folder name. :-(
or it can?..... :-\
Where the resources intersect, is that they are loaded into the same address space. The :/ file structure is global to the application. If you add to it from a plugin, then clashing names for items in the resource make that only one of them will be visible, as you found out.
What I do, is that I put items for a plugin in a resource file inside their own directory. That is, you prefix all the paths in your plugin resource file with the name of your plugin. That works just fine.
bq. The :/ file structure is global to the application.
I thought the same, but I expected plugin's resource is accessible from this plugin only. I don't remember anything about this in docs.
bq. That is, you prefix all the paths in your plugin resource file with the name of your plugin.
I just created different prefixes in .qrc files. Works fine.
If plugins will develop different people - then nothing prevents them make same names of plugins, icons and folders... I think use UID for plugin identification. May be same I will use for icons.
bq. but the code is different DLLs! the code is different!
A plugin is simply a shared library. If you load two shared libraries into the address space of you application then you also load the resources of these plugins into this address space. That means you have two resources with the same name in the adress space of your application. So this will not work.
You can choose any prefix for your resources. We prefer the plugin name here because each plugin should have a unique name to avoid equal plugin file names. So choosing the plugin filename as prefix for resources works fine for us.
bq. A plugin is simply a shared library
I have a "bad habit" think that shared library is exactly an executable just with unresolved external links. That assumes resources are located inside this executable. Probably you know where from this habit appeared... This is my first time working with plugins in Qt. Need to change some conceptions.