Results 1 to 20 of 23

Thread: How to use QLibrary?

Hybrid View

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

    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
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    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
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 7 Times in 7 Posts

    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
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    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
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    2

    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,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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
  •  
Qt is a trademark of The Qt Company.