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. How to add third party library .DLL in QT project
Forum Updated to NodeBB v4.3 + New Features

How to add third party library .DLL in QT project

Scheduled Pinned Locked Moved General and Desktop
12 Posts 6 Posters 16.1k 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.
  • Chris KawaC Offline
    Chris KawaC Offline
    Chris Kawa
    Lifetime Qt Champion
    wrote on last edited by
    #2

    Hi, welcome to devnet.

    To link to external library you either need the .dll, the .lib/.a and the header, in which case you use the above wizard, or use "QLibrary":http://doc.qt.io/qt-5/qlibrary.html to load the .dll dynamically and resolve entry points manually.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      m.sarfraz
      wrote on last edited by
      #3

      Thanks Chris for your reply.

      In QT 5.4 this wizard has no option to select .DLL type of file. It is fixed to .a or .lib type.
      I am running QT 5.4 on Windows 8.1.

      Am I using wizard correctly or can it be a Bug in QT 5.4 environment ?

      Thanks
      Muhammad

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

        Hi and welcome to devnet,

        If you want to link against your 3rd party library, then it's either the lib or a files. You don't link against dlls

        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
        • M Offline
          M Offline
          m.sarfraz
          wrote on last edited by
          #5

          Hi SGaist,

          Thanks for your reply.

          Can you please tell me how to use third party .dll in QT ? any example ?

          Thanks
          Muhammad

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #6

            if you use the wizard like already mentioned you link against this DLL file as an dependency.
            Meaning your application can't even start without it and automatically loads it if it's found or displays an error message if not.

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • M Offline
              M Offline
              m.sarfraz
              wrote on last edited by
              #7

              How can i use third party .DLL ? any example?

              1 Reply Last reply
              0
              • hskoglundH Offline
                hskoglundH Offline
                hskoglund
                wrote on last edited by
                #8

                Hi, just tested using a 3rd party DLL with Qt, it's pretty straightforward:
                I choose to test an old DLL present in Windows XP for the FreeCell game, called cards.dll, if you don't have Windows XP you can download the dll "here":http://www.dlldump.com/download-dll-files_new.php/dllfiles/C/cards.dll/5.1.2600.0/download.html The site looks suspicious but I checked, if you click to the right (Click Here to Download cards.zip) you'll get the exact same cards.dll that's in C:\Windows\System32 in Windows XP.

                For this example I put cards.dll in C:\Downloads. Also you need to know about the function(s) you are calling, in this case I googled for a description of the functions inside cards.dll, I use 2: cdtInit and cdtDraw.

                Create a new Widgets app, first insert CONFIG += c++11 in your .pro file to turn on C++11 features, then goto your mainwindow.cpp, insert these includes:
                @
                #include "QLibrary"
                #include "QTimer"
                #include "windows.h"
                @

                then below ui->setupUi(this); insert this fancy code:
                @
                ((int (WINAPI*)(int*,int*)) QLibrary("C:/Downloads/cards.dll").resolve("cdtInit"))(new int, new int);
                QTimer* pTimer = new QTimer(this);
                pTimer->start(500);
                connect(pTimer,&QTimer::timeout,
                {
                auto GetDC = (int (WINAPI *)(int)) QLibrary("user32.dll").resolve("GetDC");
                auto cdtDraw = (int (WINAPI *)(int,int,int,int,int,int)) QLibrary("C:/Downloads/cards.dll").resolve("cdtDraw");
                cdtDraw(GetDC(0),rand() % 1000,rand() % 1000,rand() % 52,0,0);
                });
                @

                If you do it right you'll get lots of cards drawn on your screen like this: !http://www.tripleboot.org/Pictures/DLLTest.png(Lots of cards)!

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  alex_malyu
                  wrote on last edited by
                  #9

                  I just want to add that normally you do not use random 3rd party dll.
                  If you are legally allowed to use it you will have access to headers files you need and associated lib files or would be able to build them.

                  That means that you do not need to use QLibrary or in other way to resolve calls. you will include appropriate header and link against appropriate lib file
                  Dll and call functions like they were in your module. Dll will be loaded by your exe at runtime. You will have to provide it with your code.

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

                    I agree with the random part however, that technique is perfectly fine otherwise and Qt uses it for e.g. OpenSSL by default

                    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
                    • M Offline
                      M Offline
                      m.sarfraz
                      wrote on last edited by
                      #11

                      Thanks for your reply Robot Herder, Ant Farmer and Mad Scientist.

                      Is there any difference if i want to use this .dll for mobile app (Android and Windows)?

                      for example can i use card.dll in Android app and get same results ?

                      Thanks and Regards

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

                        No you can't that dll uses Win32 specific API

                        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

                        • Login

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