PDA

View Full Version : QT with DLL ?



digog
18th October 2010, 16:18
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.

Lykurg
18th October 2010, 16:35
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.

digog
18th October 2010, 16:59
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

Lykurg
18th October 2010, 17:02
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.

tbscope
18th October 2010, 17:03
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?

digog
19th October 2010, 03:07
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

Lykurg
19th October 2010, 07:14
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.

digog
19th October 2010, 23:43
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?

squidge
20th October 2010, 00:08
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.

schnitzel
20th October 2010, 00:28
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.

digog
20th October 2010, 16:04
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.

schnitzel
21st October 2010, 01:32
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:



LIBS += path/to/library/yourlib.a


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.

digog
3rd November 2010, 04:35
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?