Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    [SOLVED] QPluginLoader unable to load a Qt Plugin

    General and Desktop
    qtplugin plugin loader interface
    3
    9
    8064
    Loading More Posts
    • 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.
    • B
      bharath144 last edited by bharath144

      Hello all,

      I have an Interface as shown below.

      class MyInterface
      {
          public:
              virtual ~MyInterface() {}
              virtual int initialize() = 0;
      };
      
      Q_DECLARE_INTERFACE(MyInterface, "com.example.MyInterface/1.0")
      

      My plugin implements this interface and declares it in its class as shown below.

      class QT_DECL_EXPORT MyPlugin : public QObject, public MyInterface
      {
          Q_OBJECT
          Q_INTERFACES(MyInterface)
      
          public:
              MyPlugin();
              virtual ~MyPlugin();
      
          public:
              int initialize();
      
              // ...
      };
      

      My plugin's project file sets the target appropriately.

      TARGET = $$qtLibraryTarget(MyPlugin)
      TEMPLATE = lib
      

      Now, all the modules (including my app) gets compiled. In the app where I have to load the plugin, I have the following code:

      // ...
      
      QPluginLoader loader("MyPluginld.dll");
      if (! loader.load())
          qDebug() << "Error!";
      
      MyInterface *base = qobject_cast<MyInterface *>(loader.instance());
      if (base == NULL)
          qDebug() << "Error!";
      
      // ...
      

      The loader.load() function always fails. Am I making a mistake by providing incorrect name to the QPluginLoader constructor? Or is something else wrong?

      Any help would be much appreciated.

      Cheers!
      Bharath

      Cheers!
      ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
      Bharath Narayan M G

      1 Reply Last reply Reply Quote 0
      • M
        mcosta last edited by

        In your code you expect that the DLL is in the same directory of the executable.
        Is that TRUE??

        Once your problem is solved don't forget to:

        • Mark the thread as SOLVED using the Topic Tool menu
        • Vote up the answer(s) that helped you to solve the issue

        You can embed images using (http://imgur.com/) or (http://postimage.org/)

        B 1 Reply Last reply Reply Quote 0
        • B
          bharath144 @mcosta last edited by

          @mcosta Yes, that is correct. My deployment model ensures that both land up in the same directory.

          Cheers!
          ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
          Bharath Narayan M G

          Cheers!
          ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
          Bharath Narayan M G

          1 Reply Last reply Reply Quote 0
          • M
            mcosta last edited by

            Hi,

            if your DLL is in the right place you can use QPluginLoader::errorString()to understand why load fails

            Once your problem is solved don't forget to:

            • Mark the thread as SOLVED using the Topic Tool menu
            • Vote up the answer(s) that helped you to solve the issue

            You can embed images using (http://imgur.com/) or (http://postimage.org/)

            B 2 Replies Last reply Reply Quote 0
            • B
              bharath144 @mcosta last edited by

              @mcosta Thanks for that. I will see what the error string says.

              Cheers!
              ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
              Bharath Narayan M G

              1 Reply Last reply Reply Quote 0
              • B
                bharath144 @mcosta last edited by bharath144

                @mcosta
                The errorString prints the following:

                "Plugin verification data mismatch in './/MyPluginld.dll'"
                

                Cheers!
                ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
                Bharath Narayan M G

                1 Reply Last reply Reply Quote 0
                • M
                  mcosta last edited by

                  @bharath144 said:

                  Plugin verification data mismatch in

                  Had a quick look to Qt sources.
                  Seems that you must use this macro to define plugin's metadata.

                  Reading here, the point 3. of "Writing a plugin involves these steps:" says the same thing

                  Once your problem is solved don't forget to:

                  • Mark the thread as SOLVED using the Topic Tool menu
                  • Vote up the answer(s) that helped you to solve the issue

                  You can embed images using (http://imgur.com/) or (http://postimage.org/)

                  B 1 Reply Last reply Reply Quote 1
                  • B
                    bharath144 @mcosta last edited by

                    @mcosta That did the trick. I saw the step but I overlooked it thinking it may not be mandatory.

                    Thanks for the help.

                    Cheers!
                    ಮೈ ಗೋ ಭರತ ನಾರಾಯಣ
                    Bharath Narayan M G

                    1 Reply Last reply Reply Quote 0
                    • L
                      LeaA last edited by LeaA

                      hello,

                      can you tell us how you solve your problem?
                      thank you.

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post