Can QPlugins safely be used in a static/shared library project?



  • Hi all,

    first of all some background:

    I'm developing a voice library in C++. It should be cross platform and support different codecs (Opus, Speex, etc) as well as different sound drivers (DirectSound, PulseAudio, CoreAudio etc).

    I started with the typical approach by designing an abstract interface, lets say ICodec. This interface is pure virtual.

    Now I have the typical problem as many other projects, how do I register the different codecs to my managing class.
    The easiest way is to hard code the available codes in a enum and pass this to the create method

    @
    enum ECodecs{ SPEEX = 1,
    OPUS,
    [...] };

    ICodec *CCodecFactory::create (ECodecs codec)
    {
    ICodec *codecObj;
    switch (codec)
    {
    case SPEEX:
    codecObj = createSpeexCodec();
    break;

        case OPUS:
             codecObj = createOpusCodec();
        break;
        [....]
    
       return codecObj;
    

    }
    @

    But this is a pain if you want to add new codecs later.
    An also very common approach is to use a factory object, which registers itself to the manager in its constructor. To make this work, you need a static global object, otherwise the constructor gets never called.

    @
    CSpeexCreator g_speexCreator;

    [...]

    CSpeexCreator::CSpeexCreator(const QString &name)
    {
    CCodecManger::register(name, this);
    }
    @

    but this is highly nonstandard and you never can be sure, what happens, so I don't really like this approach.

    Now to my question:
    From my point of view, the Qt plugin framework would fit perfectly. The implementations could be done in plugins. Codecs could be removed and added via plugins without the need to rebuild the whole library.

    But is it safe to use Qt plugin in a library project or should not use it? The library I'm developing is not a application but only a library providing voice client implementations.
    Are there any objections?



  • Does nobody have an answer? The design can't be that unconventional ;)


  • Lifetime Qt Champion

    Hi,

    No it's not, if you look through Qt's sources you'll see it's what they use for example with QtMultimedia (thinking of the backends)

    Nothing forbids you to do it :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.