Page 1 of 2 12 LastLast
Results 1 to 20 of 23

Thread: How to use QLibrary?

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

    Default How to use QLibrary?

    Hello,
    I would like to know how to use the QLibrary to read a DLL library and call its functions.
    I'll appreciate if someone could give me an example.

    Thanks

  2. #2
    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: How to use QLibrary?

    You don't use QLibrary to use a DLL in your application.

    Just include the header file of the library, and link the library to your application.

    Note that you can not use QLibrary to easily load C++ symbols. So, if your library is written in C++ and it doesn't extern C its symbols, you'll need a bit of work to get the correct symbols.

  3. #3
    Join Date
    Jun 2010
    Location
    Pretoria, South Africa
    Posts
    22
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to use QLibrary?

    You cannot use QLibrary to scan a shared library to see what symbols it has. You need to get that list from the library's creator.

    Once you know what's inside the library, you need to know the types of the symbols that you wish to access. These could be functions, classes or variables. In the case of functions, you need to know the function signature, in the case of classes, you need the class definition and in the case of variables, you need to have the data type. All these should be supplied by the creators in header files and/or DEF files.

    Once you've decided what you need, you can load the library into memory using QLibrary (see Assistant) and then find the symbol's address using QLibrary::resolve(), converting the void* to the data type that the symbol represents.

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

    Default Re: How to use QLibrary?

    how about if I use the function LoadLibrary? is that supported by QT?


    Added after 11 minutes:


    Quote Originally Posted by Robbie View Post
    You cannot use QLibrary to scan a shared library to see what symbols it has. You need to get that list from the library's creator.

    Once you know what's inside the library, you need to know the types of the symbols that you wish to access. These could be functions, classes or variables. In the case of functions, you need to know the function signature, in the case of classes, you need the class definition and in the case of variables, you need to have the data type. All these should be supplied by the creators in header files and/or DEF files.

    Once you've decided what you need, you can load the library into memory using QLibrary (see Assistant) and then find the symbol's address using QLibrary::resolve(), converting the void* to the data type that the symbol represents.
    Thanks for the reply Robbie.
    I already know what is inside the library. I'm talking about the mpusbapi.dll from microchip, I already have all the headers and sources code but specific to the boorland c++ builder compiler, so from there I can get the list of the function that I want to use.
    How can I proceed from here? I need to make a DEF file?
    Last edited by digog; 3rd November 2010 at 15:09.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QLibrary?

    Quote Originally Posted by digog View Post
    how about if I use the function LoadLibrary? is that supported by QT?
    What is it that you really want to do with the library? Why can't you link your program against it during compilation?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: How to use QLibrary?

    Quote Originally Posted by wysota View Post
    What is it that you really want to do with the library? Why can't you link your program against it during compilation?
    I cant link during compilation cause I just have the dll file I dont know how to get the .h file from it.
    I'll be glad if you could explain me how.
    Last edited by digog; 3rd November 2010 at 15:35.

  7. #7
    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: How to use QLibrary?

    Quote Originally Posted by digog View Post
    I dont know how to get the .h file from it.
    I already have all the headers
    I guess there's something fundamental you do not understand.

    You have the DLL, that's ok.
    You have the headers (.h file) that's great.

    Now, include the header file in your own source code and link the dll with your program.
    Something in the lines of LIBS += -lmpusbapi should be added to your .pro file

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QLibrary?

    I think what he really lacks is the import library but as far as I know this can be regenerated from the dll.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: How to use QLibrary?

    Quote Originally Posted by tbscope View Post
    You have the DLL, that's ok.
    Thats ok.

    You have the headers (.h file) that's great.
    The .h file is specific to the borland c++ compiler. I don't know if I can just include this .h file in my own project.

    link the dll with your program.
    Something in the lines of LIBS += -lmpusbapi should be added to your .pro file
    dont I need to have the .lib file for this? I have one here but, as I said before, its specific to the borland c++ compiler.

    Sorry if I making a big confusion, its just all new for me.

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QLibrary?

    Quote Originally Posted by digog View Post
    The .h file is specific to the borland c++ compiler. I don't know if I can just include this .h file in my own project.
    The .h file holds the function prototypes which you will need with QLibrary too. So this is a problem you will have to resolve either way.

    dont I need to have the .lib file for this? I have one here but, as I said before, its specific to the borland c++ compiler.
    http://jrfonseca.planetaclix.pt/proj...imp/index.html
    I'm sure there is an equivalent for Turbo C++.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: How to use QLibrary?

    http://jrfonseca.planetaclix.pt/proj...imp/index.html
    I'm sure there is an equivalent for Turbo C++.
    What should I do with it?

  12. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QLibrary?

    Reconstruct the import library from the dll.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: How to use QLibrary?

    Quote Originally Posted by wysota View Post
    Reconstruct the import library from the dll.
    Isn't there a tutorial?

    And do you think that this program, that I found on internet, can resolve my problem?
    Here is the link:
    http://www.softpedia.com/get/Program...L-to-Lib.shtml
    Last edited by digog; 4th November 2010 at 14:58.

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QLibrary?

    Quote Originally Posted by digog View Post
    Isn't there a tutorial?
    Did you find the appropriate program?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: How to use QLibrary?

    Quote Originally Posted by wysota View Post
    Did you find the appropriate program?
    I downloaded the mingw-get-inst-20101030 and mingw-utils-0.3.tar.gz. Is those the right programs?
    Last edited by digog; 5th November 2010 at 00:47.

  16. #16
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QLibrary?

    Quote Originally Posted by digog View Post
    I downloaded the mingw-get-inst-20101030 and mingw-utils-0.3.tar.gz. Is those the right programs?
    I don't know, is there a tool there that can create an import library for MinGW from a Borland DLL?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    Default Re: How to use QLibrary?

    Quote Originally Posted by wysota View Post
    I don't know, is there a tool there that can create an import library for MinGW from a Borland DLL?
    The dll is not a Borland DLL, it is compiler independent as you can see in the readme file that comes with the dll:
    Release Notes for MPUSBAPI Library, Microchip Technology Inc.
    v1.00
    19 November 2004

    ----------------------------------------------------------------------
    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.
    So I think that I just need a program that could create an import library compatible with MinGW, right?
    What about the dlltool? can it resolve my problem?

  18. #18
    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: How to use QLibrary?

    If a different compiler is used, however, the DLL must be re-compiled to generate a new mpusbapi.lib specific to that compiler.
    As easy as that.

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

    Default Re: How to use QLibrary?

    Quote Originally Posted by tbscope View Post
    As easy as that.
    Ok, so we are close now.
    Do you know any tool that can do it? In other words, create an import library compatible with MinGW?

  20. #20
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to use QLibrary?

    Quote Originally Posted by digog View Post
    Do you know any tool that can do it? In other words, create an import library compatible with MinGW?
    Yes, it's called a "compiler". It takes the source code as input and outputs the import library and runtime library.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. QLibrary in PyQt
    By Urthas in forum Qt Programming
    Replies: 0
    Last Post: 30th October 2009, 18:46
  2. QLibrary resolve problem
    By Nippler in forum Qt Programming
    Replies: 0
    Last Post: 4th December 2008, 15:37
  3. Using Qlibrary on a function that uses arguments
    By schall_l in forum Qt Programming
    Replies: 8
    Last Post: 9th September 2008, 21:58
  4. The problem with QLibrary, help me!
    By dungsivn in forum Qt Programming
    Replies: 4
    Last Post: 17th January 2008, 14:03
  5. Qlibrary
    By rianquinn in forum Qt Programming
    Replies: 5
    Last Post: 4th February 2006, 12:23

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.