Results 1 to 13 of 13

Thread: QT with DLL ?

  1. #1
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default QT with DLL ?

    Hi, I am new to QT development and windows application development.
    Sorry for this really noob question but I didn't find anything on the web

    The question is can I use DLL files in my QT development ? And how can I do this?
    I want to link my application with the DLL at build-time.
    I am using the opensource QT.

    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QT with DLL ?

    You can since Qt is pure C++. Include the header files as normal and see the LIBS variable for your pro file. (qmake documentation) Also search this forum, there a several thread about using custom libraries with Qt.

  3. #3
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT with DLL ?

    Thanks for the answer.
    But my problem is that I have only the DLL file (not .lib or .h files) and I don't know how to add it to my project.

    Can you please show me where in this forum i can find this thread?

    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QT with DLL ?

    Quote Originally Posted by digog View Post
    But my problem is that I have only the DLL file (not .lib or .h files) and I don't know how to add it to my project.
    Ehm, but you need the header files. Which dll you are talking about?

    Can you please show me where in this forum i can find this thread?
    There are many and I havn't had a specific in mind.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: QT with DLL ?

    To be able to use the library, you need the prototypes of the functions and classes inside the library. In other words, you need a header file (.h file)

    Which library do you want to use?

  6. #6
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT with DLL ?

    Quote Originally Posted by tbscope View Post
    Which library do you want to use?
    I want to use a library called mpusbapi.dll for usb communication.

    The prototypes of the functions and classes I have are specific to the boorland c++ compiler. At least its what is written in the readme file that comes with the library.

    README FILE:
    ----------------------------------------------------------------------
    1. What is MPUSBAPI Library?
    ----------------------------------------------------------------------

    * MPUSBAPI is a DLL module providing wrapper functions for the
    Microchip General Purpose USB Windows driver, mchpusb.sys.
    It abstracts out the complexity in working with Win32 API functions.

    * Seven basic functions are provided in this release:

    - MPUSBGetDeviceCount

    - MPUSBOpen

    - MPUSBClose

    - MPUSBRead

    - MPUSBReadInt

    - MPUSBWrite

    - MPUSBGetDLLVersion

    * Details on how to use each function are documented in the source code
    - Refer to \DLL\Borland_C\Source\_mpusbapi.cpp

    ----------------------------------------------------------------------
    2. Linking MPUSBAPI to your project
    ----------------------------------------------------------------------

    There are two ways to link the DLL to your project:

    a) Load-time Linking

    Simply add the mpusbapi.lib file to your project.
    The mpusbapi.lib file provided is specific to the Borland C++
    compiler. The mpusbapi.dll is compiler independent. If a different
    compiler is used, however, the DLL must be re-compiled to generate
    a new mpusbapi.lib specific to that compiler.


    C++ source code for MPUSBAPI is provided.

    The _mpusbapi.h file must be included in every file that uses
    the MPUSBAPI functions.

    The mpusbapi.dll file must be in the same directory as the
    executable file.

    b) Run-time Linking

    Run-time Linking does not require the .lib file. It only requires
    the .dll file. Linking the functions is, however, a little more
    complicated. An example is provided showing how to use Win32
    API functions to load a DLL.

    The mpusbapi.h file (note, no "_") must be included in every file
    that uses the MPUSBAPI functions.

    The mpusbapi.dll is not required to be in the same directory as
    the executable file.
    I don't know how to re-compile the DLL to generate a new mpusbapi.lib specific to Qt
    or if I can use the existing mpusbapi.lib file.

    Thanks

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QT with DLL ?

    You don't have to compile it for Qt: The mpusbapi.dll is compiler independent! Also one sentence later:
    C++ source code for MPUSBAPI is provided.

    The _mpusbapi.h file must be included in every file that uses
    the MPUSBAPI functions.

    The mpusbapi.dll file must be in the same directory as the
    executable file.
    What do you need more? Have a look at LIBS in the qmake documentation. If you need the lib then you have to compile the provided sources with your compiler. Build instruction can surly be found inside the project.

  8. #8
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT with DLL ?

    So I get the sources but I still don't know to compile the sources with my compiler to get the lib.
    Can anyone help me with this part?

  9. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT with DLL ?

    That is both compiler and architecture specific, and clearly outside the scope of these forums.

    But Instructions will be contained in a README file or similar.

  10. #10
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QT with DLL ?

    That's a very basic question - get your hands on a C++ book. Try the online book referenced here:
    http://doc.qt.nokia.com/4.7/how-to-learn-qt.html


    1) Have you tried mingw-utils - reimp and dlltool to create an import lib? Make sure you use the 0.3 version, not the latest.

    2) You might want to create a new project of type 'C++ Library' in Qt Creator. Then, assuming the source code you have is portable, add all cpp and h files to the project.

    3) You can also learn a lot from looking at how other projects work, for example qextserialport.

  11. #11
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT with DLL ?

    Quote Originally Posted by schnitzel View Post
    2) You might want to create a new project of type 'C++ Library' in Qt Creator. Then, assuming the source code you have is portable, add all cpp and h files to the project.
    I'm not sure if the source code is portable, but I did it. It created a .a file not a .lib file.

    3) You can also learn a lot from looking at how other projects work, for example qextserialport.
    Didn't find this example.

  12. #12
    Join Date
    Oct 2009
    Posts
    364
    Thanks
    10
    Thanked 37 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QT with DLL ?

    Ok, if you created the .a file, then you should be able to link it to your app by specifying the following in your .pro file:

    Qt Code:
    1. LIBS += path/to/library/yourlib.a
    To copy to clipboard, switch view to plain text mode 

    about the qextserialport project, you can find it here: http://code.google.com/p/qextserialport/

    I have successfully built that library as dynamic and static.

  13. #13
    Join Date
    Aug 2010
    Posts
    32
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QT with DLL ?

    Quote Originally Posted by schnitzel View Post
    I have successfully built that library as dynamic and static.
    What library you are talking about? mpusbapi?

    And another question is if I want to link that library at run-time can I use the QLibrary?
    Last edited by digog; 3rd November 2010 at 03:42.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.