PDA

View Full Version : How can I contact a DLL using Qt.



srohit24
17th February 2009, 06:11
I am working on a project that relies on contacting Dll's.

I would like to know how I can contact a Dll, say one that holds information from a hardware and I need to use it somewhere else. How can i do that using Qt.

if the above method is not possible, I want to know how a Gcc compiler in windows can contact a DLL.

I havent written much code, i have been using the designer. Now i want to convert .ui files so that i can have a .cpp file. Can that be done??

talk2amulya
17th February 2009, 06:16
whenever u wanna use a function from a dll, u should know which file of dll it is in..include its .h file..and also add its library file in the linking process...read about dlls and lib carefully..qt also can create dll and lib(when working on windows)..bottomline is QT is a C++ framework, so anth that u can do in C++, u can do in QT

u can compile ur .ui file, it will create a .h file

srohit24
17th February 2009, 13:29
thanks for replying.

I got the .h file after i compiled the .ui files.

Consider that i need to make a change in the .h files, say add a function and i add it. how can I load it again in the designer?

How can i get a .exe of the .ui file? i tried to compile the .h file, but it says error and no .exe file is created.

Before I add a Dll function,I should know the name of the function that i am using? cant i just add the whole dll??

Can you eloborate on linking process? how i can link the dll libs during run time and such?

thanks again.

stevey
19th February 2009, 04:58
First off, you need to consider the .h file generated by compiling the .ui a file you never modify. Always subclass the form defined in the .h file, then you make changes there. That way you can re-generate the .ui whenever you need to, which CAN be often especially in the early stages of development.

How can i get a .exe of the .ui file? i tried to compile the .h file, but it says error and no .exe file is created.
There are plenty of example in the Qt documentation for using the qmake system to generate exes, dlls, etc.

If you intend on using a dll, then you can only make calls into it if you know the function names and signatures. This will usually be defined in the .h file accompanying the dll. If you don't actually have a .h file, then you can make 'extern' statements declaring the signatures in your own code, but you need to know the signatures first.

For linking, at least using Visual Studio's compilers you need a .lib file as well as the dll.
If you're a statically linked file the .lib will contain all the code and be very big. If it's dll, then the .lib will be tiny containing only the locations in the dll of the symbols which have bee "exported". So in you're own project you'd #include the header file for the dll's symbols and link to the small .lib file. At run time, as long as you drop the dll somewhere in the PATH, usually just alongside the exe then it will be called.

I can't remember exactly what happens with GCC / MinGW in terms of if you need a .o file accompanying the dll, but you specify the lib path and target with options -L<path> and -l<libname>
It's not the whole <libname> though, for example if you have libstuff you'd just put -lstuff (Someone correct me please if I'm missing anything here, it's been a while).



Steve York