Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Load plugin depending on file extension

Load plugin depending on file extension

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 2.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    ahenric
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pmlit
      wrote on last edited by
      #2

      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;
      

      }
      @

      1 Reply Last reply
      0
      • L Offline
        L Offline
        lgeyer
        wrote on last edited by
        #3

        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)
        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          [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).

          1 Reply Last reply
          0
          • P Offline
            P Offline
            pmlit
            wrote on last edited by
            #5

            [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 ?

            1 Reply Last reply
            0
            • L Offline
              L Offline
              lgeyer
              wrote on last edited by
              #6

              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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved