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. Qt Pluggin issue
Forum Updated to NodeBB v4.3 + New Features

Qt Pluggin issue

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.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.
  • BlackMambaB Offline
    BlackMambaB Offline
    BlackMamba
    wrote on last edited by
    #1

    Hello,
    I have a question regarding Qt Pluggin.
    I am doing a little audio application which plays sounds (and other stuff) from instruments.
    I have an abstract class Instrument and the instruments subclass this Instrument class for exemple Piano, etc ...
    I want to make some of these instruments available as plugins. For example I created Violon.dll as Qt Plugin when I do a new Violin in my code its working fine.
    However, if after the release of the binary, I want to create another instrument lets say Cello, I won't be able to write the piece of code with Instrument* instrument = new Cello.
    How could I make that working if I don't know before the release, the instruments I will create after the release of the binary?
    Cheers,

    1 Reply Last reply
    0
    • BlackMambaB Offline
      BlackMambaB Offline
      BlackMamba
      wrote on last edited by
      #2

      For example, here is a piece of code I found...

      @QObject *plugin = pluginLoader.instance();
      if (plugin) {
      myInstrument = qobject_cast<Instrument *>(plugin);@

      The only issue I have is that I have a menu in the GUI which is showing all the instruments available. I can dynamically add the new instrument names to this list using myInstrument->getName() but can I say if you click on "Cello" in the menu it creates a Cello, etc ... Cause to do myInstrument->getName() you already have an instance of an implemented Instrument... It's messy for me :(

      1 Reply Last reply
      0
      • BlackMambaB Offline
        BlackMambaB Offline
        BlackMamba
        wrote on last edited by
        #3

        Can this work :
        You create an instance of all the instrument pluggins to have access to their name and load the names in the GUI menu.
        @foreach (QString fileName, pluginsDir.entryList(QDir::Files)) {
        QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(fileName));
        QObject *plugin = pluginLoader.instance();
        if (plugin) {
        myInstrument = qobject_cast<Instrument *>(plugin);
        if (myInstrument)
        return true;
        }
        }
        @

        Then call createInstrument(QString name):

        @void createInstrument(QString name){
        // assuming the instrumentName is the same as the dll file name
        QPluginLoader pluginLoader(pluginsDir.absoluteFilePath(name));
        QObject *plugin = pluginLoader.instance();
        if (plugin) {
        myInstrument = qobject_cast<Instrument *>(plugin);

        @}

        Should this work?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Did you take a look at the "Plug and Paint" example ? It seems to fit your use case

          Hope it helps

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • BlackMambaB Offline
            BlackMambaB Offline
            BlackMamba
            wrote on last edited by
            #5

            Hello SGaist,
            Didn't have a look at that particular exemple.
            Thank you very much,
            Cheers

            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