For some reasons, I must work with Qt3 under SLES 11 SP3. I have written the following plugin:
// PixmapButtonPlugin.hpp
#include <qwidgetplugin.h>
class PixmapButtonPlugin : public QWidgetPlugin
{
public:
QStringList keys () const;
QWidget* create (const QString& key, QWidget* parent = 0, const char* name = 0);
QString group (const QString& key) const;
QIconSet iconSet (const QString& key) const;
QString includeFile (const QString& key) const;
QString toolTip (const QString& key) const;
QString whatsThis (const QString& key) const;
bool isContainer (const QString& key) const;
};
Q_EXPORT_PLUGIN(PixmapButtonPlugin)
// PixmapButtonPlugin.cpp
#include "PixmapButtonPlugin.hpp"
#include "PixmapButton.qh"
QStringList PixmapButtonPlugin::keys () const
{
return QStringList() << "PixmapButton";
}
QWidget* PixmapButtonPlugin::create (const QString&, QWidget* parent, const char*)
{
return new PixmapButton(parent);
}
QString PixmapButtonPlugin::group (const QString&) const
{
return "Buttons";
}
QIconSet PixmapButtonPlugin::iconSet (const QString& key) const
{
return QWidgetPlugin::iconSet(key);
}
QString PixmapButtonPlugin::includeFile (const QString&) const
{
return "PixmapButton.qh";
}
QString PixmapButtonPlugin::toolTip (const QString&) const
{
return "Pixmap button";
}
QString PixmapButtonPlugin::whatsThis (const QString&) const
{
return "Button that takes the shape of its pixmap";
}
bool PixmapButtonPlugin::isContainer (const QString&) const
{
return false;
}
I have finally copied the compiled shared library libplugins.so in the folder
/usr/lib/qt3/plugins/designer
The designer doesn't display the plugins anywhere and doesn't tell me that it couldn't create the corresponding widget either. I get absolutely no error.
What should I do?
I got some help at work from a senior developer and actually found a way out of this problem. The main issue here is to make sure that the plugin is ok. How can I check that everything is fine with my plugin? That's pretty simple.
First, compile the following simple application:
// PluginLoader.cpp
#include <iostream>
#include <qlibrary.h>
#include <private/qcom_p.h>
int main(int argc, char *argv[])
{
QLibrary lib("/path-to-my-plugin/myPlugin.so");
std::cout << "Load: " << lib.load() << std::endl;
std::cout << "Resolve: " << (lib.resolve("ucm_instantiate") != 0) << std::endl;
return 0;
}
Second, activate some debugging tools for libraries: type the following commands in a console
export LD_WARN=1
export LD_VERBOSE=1
export LD_DEBUG=all
Note that there are many other options than "all" for the LD_DEBUG variable. Just type
export LD_DEBUG=help
to get more details (you will get the details as soon as you launch the above application).
Then, launch the PluginLoader application
./PluginLoader 2> loader.log
The file loader.log will then contain all the details regarding the libraries that are being loaded, in particular messages starting with
symbol lookup error
which indicate that something is missing in the plugin.
When the PluginLoader is happy, i.e. when it says
Load: 1
Resolve: 1
you are normally ready to use the plugin in the Qt Designer. To use it, copy it in the folder
/usr/lib/qt3/plugins/designer
or
$QTDIR/plugins/designer
which is the default folder for the designer's plugins. You may also be successful by setting the
LD_LIBRARY_PATH
QT_PLUGIN_PATH
appropriately.
Usually, you can also simply
ldd /path-to-your-plugin/myPlugin.so
This will show you which libraries this plugin was linked against. This can provide you with information about libraries that you may have forgotten ...
And a last comment. I am developing on SLES 11 SP3 64 bits. However, I am compiling 32-bits applications. In particular, the plugin is 32 bits. Before trying to let the plugin appear in the designer, make sure that the designer is the 32-bit version. Otherwise, the plugin won't appear in the list.
Note also that this process can also be applied to the production of Qt4 and Qt5 plugins (maybe modulo a few adaptions)!