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. [SOLVED] QPluginLoader unable to load a Qt Plugin
QtWS25 Last Chance

[SOLVED] QPluginLoader unable to load a Qt Plugin

Scheduled Pinned Locked Moved General and Desktop
qtpluginpluginloaderinterface
9 Posts 3 Posters 9.7k Views
  • 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 Offline
    B Offline
    bharath144
    wrote on 27 Mar 2015, 13:36 last edited by bharath144
    #1

    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
    0
    • M Offline
      M Offline
      mcosta
      wrote on 27 Mar 2015, 20:10 last edited by
      #2

      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 30 Mar 2015, 05:57
      0
      • M mcosta
        27 Mar 2015, 20:10

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

        B Offline
        B Offline
        bharath144
        wrote on 30 Mar 2015, 05:57 last edited by
        #3

        @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
        0
        • M Offline
          M Offline
          mcosta
          wrote on 30 Mar 2015, 06:18 last edited by
          #4

          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 30 Mar 2015, 06:34
          0
          • M mcosta
            30 Mar 2015, 06:18

            Hi,

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

            B Offline
            B Offline
            bharath144
            wrote on 30 Mar 2015, 06:34 last edited by
            #5

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

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

            1 Reply Last reply
            0
            • M mcosta
              30 Mar 2015, 06:18

              Hi,

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

              B Offline
              B Offline
              bharath144
              wrote on 30 Mar 2015, 06:37 last edited by bharath144
              #6

              @mcosta
              The errorString prints the following:

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

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

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mcosta
                wrote on 30 Mar 2015, 07:21 last edited by
                #7

                @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 30 Mar 2015, 09:46
                1
                • M mcosta
                  30 Mar 2015, 07:21

                  @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

                  B Offline
                  B Offline
                  bharath144
                  wrote on 30 Mar 2015, 09:46 last edited by
                  #8

                  @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
                  0
                  • L Offline
                    L Offline
                    LeaA
                    wrote on 11 May 2015, 09:06 last edited by LeaA 5 Dec 2015, 07:08
                    #9

                    hello,

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

                    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