Load plugin depending on file extension



  • Hi,

    if I have multiple plugins for one interface, how can I distinguish between them? I basically want to load one plugin for the interface depending on the file extension of a file that is opened.

    Must one basically get the instance (QPluginLoader, which loads a plugin), have each plugin have a function to return its name, if this does not match the file extension, unload the plugin and try the next one? Or is there a simpler way?

    Thanks



  • try that :
    @switch (fileName.section('.', -1, -1))/* file extension /
    {
    case "abc" :// for "something.abc" files
    /
    load your file using QPluginLoader */
    break;

    case "xyz" :// for "plugin.xyz" files
        /* load your file the way you want */
    break;
    

    }
    @



  • You can either

    • load the plugin and determine the supported extension (as you suggested)
    • encode the supported extension in the filename (eg. plugin_jpg.dll, plugin_bmp.dll)
    • distribute and additional file which contains the supported extension (like QtCreators .pluginspec)


  • [quote author="pmlit" date="1340383889"]
    @switch (fileName.section('.', -1, -1))/* file extension /
    {
    case "abc" :// for "something.abc" files
    /
    load your file using QPluginLoader */
    break;

    case "xyz" :// for "plugin.xyz" files
        /* load your file the way you want */
    break;
    

    }
    @
    [/quote]Be aware that a switch expression requires an integral type or a class type for which there is an unambiguous conversion to an integral type (or constexpr in C++11).



  • [quote author="Lukas Geyer" date="1340389040"]Be aware that a switch expression requires an integral type or a class type for which there is an unambiguous conversion to an integral type (or constexpr in C++11).
    [/quote]

    I thought it was like switching a string because section() returns a QString.
    If it do not work, you are maybe allowed to use if-else clauses, don't you ?



  • You cannot use a string (neither a std::string nor a QString) as switch expression. because it is not an intergal type. But you can of course, or better you will have to, use if ... else clauses.


Log in to reply
 

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