PDA

View Full Version : How to use a dll compiled by QT into QT



tonnot
19th November 2010, 11:16
I have seen a good explanation about create a DLL with QT to use with QT, but the author does not explain how to use inside my project.
I would want to use a function, a macro, an entire class...

I would appreciate some instructions.

squidge
19th November 2010, 11:27
How do you want to use the DLL in in your project?

Do you want your DLL to be loaded by the OS when your application is loaded? If so, you need to include the .lib file for the DLL in your .pro file. Examples of how to do this is specified in the qmake documentation.

If you want to load the DLL at runtime, then have a look at QLibrary class in Qt documentation.

tonnot
19th November 2010, 11:36
Thanks,
First I want to load DLL at runtime. QTLibrary is some abstract for me, some example please?

And, whats mean "Do you want your DLL to be loaded by the OS when your application is loaded?"
Thanks again

Timoteo
20th November 2010, 18:36
Both options load the module at runtime, but the second option (QLibrary/LoadLibrary) allows you to handle the case that the lib isn't available (even if it is just exiting gracefully and notifying the user). With the first option (using import lib), the OS module loader will simply fail to load your application in the event that the lib is not available. Using QLibrary/LoadLibrary is more robust but requires more code and more overall symbol management from the programmer.

squidge
20th November 2010, 18:59
Examples of the usage of QLibrary are in the Qt documentation also. There's no point in me copying and pasting when the information is already there.

For a more complete example, take a look at plugandpaint, also in the Qt distribution.