Using a library with a Qt Application : Need guidance/suggestions
-
Hi All,
I have been working on to create a Config Utility using Widget Classes on QtCreator 5 (MinGW version). We have an API which has the function implementations of the buttons/features available in the Config Utility. This API we want to use as a library and finally add it up to the Config Utility Qt Application. From resources available on internet, I could find some info (mainly "this link was helpful":http://qt-project.org/wiki/How_to_create_a_library_with_Qt_and_use_it_in_an_application) but it is not sufficient for a newbie like me.
So I have a few thing to clarify. Please guide me on these:
- How about building a library file using Visual Studio and using it?? Some links suggest using "dll" rather than "lib" files. Which is better??
- Is it needed/preferable to build a library with a GCC compiler for using with a Qt application because Qt Build also uses GCC??
- How to call the functions encapsulated in the library in the Qt application source code?? I could not find a proper way of calling a library function in the application code..I tried a couple of ways but got "unresolved externals" or "undefined reference" error. Please refer a link or basic syntax enough to understand the implementation.
- If a library is to be created using Qt, is C++ mandatory to be used or we can use C ?? As the APIs have been written in C.
Thanks
-
[quote author="deepak_" date="1370595338"]
I have been working on to create a Config Utility using Widget Classes on QtCreator 5 (MinGW version).
[/quote]
Just a clarification. Qt creator is an IDE only the current version is 2.7.1. The Qt creator is using also the Qt libs.
The Qt lib is what you have to use for creating dialogs and stuff. It has the current version 5.x.[quote author="deepak_" date="1370595338"]
- How about building a library file using Visual Studio and using it?? Some links suggest using "dll" rather than "lib" files. Which is better??
[/quote]
The first decision ou have to make is on the license model you like to use. Basically static libs are requiring a commercial license. But please check the license conditions.
[quote author="deepak_" date="1370595338"] - Is it needed/preferable to build a library with a GCC compiler for using with a Qt application because Qt Build also uses GCC??
[/quote]
In principle you may use any supported compiler. If you like to use pre-build libs you are bound to the supported compilers during the pre-build process.
[quote author="deepak_" date="1370595338"] - How to call the functions encapsulated in the library in the Qt application source code?? I could not find a proper way of calling a library function in the application code.. Please refer a link or basic syntax enough to understand the implementation.
- If a library is to be created using Qt, is C++ mandatory to be used or we can use C ?? As the APIs have been written in C.
[/quote]
I am not sure if understand correctly, but apparently you should familiarize yourself a bit with C++ and OOP. Plain C cannot be combined with Qt libs. At least some of C++ frame work is required. However, most for number crunching and other stuff may be certainly in plain C.
- How about building a library file using Visual Studio and using it?? Some links suggest using "dll" rather than "lib" files. Which is better??
-
Koahnig, Thanks a lot for responses. I have got a bit clear view. Still have some more queries..
[quote author="koahnig" date="1370597116"]
Just a clarification. Qt creator is an IDE only the current version is 2.7.1. It has the current version 5.x.
[quote author="deepak_" date="1370595338"]
Yes, you are right! I meant the same.
[/quote]
[/quote]-
How about building a library file using Visual Studio and using it?? Some links suggest using “dll” rather than “lib” files. Which is better??
[quote author="koahnig" date="1370595338"]
The first decision you have to make is on the license model you like to use. Basically static libs are requiring a commercial license. But please check the license conditions.
[quote author="deepak_" date="1370595338"]
I have a LGPL/GPL licensed QtCreator version. Does it mean I can use libraries as ".dll" only??
[/quote]
[/quote] -
Is it needed/preferable to build a library with a GCC compiler for using with a Qt application because Qt Build also uses GCC??
[quote author="koahnig" date="1370595338"]
In principle you may use any supported compiler. If you like to use pre-build libs you are bound to the supported compilers during the pre-build process.
[quote author="deepak_" date="1370595338"]
"you are bound to the supported compilers during the pre-build process". What do you mean by "pre-build process??" Is it pre-build for library??
[/quote]
[/quote] -
How to call the functions encapsulated in the library in the Qt application source code?? I could not find a proper way of calling a library function in the application code.. Please refer a link or basic syntax enough to understand the implementation.
[quote author="deepak_" date="1370595338"]
I tried a couple of methods available on internet but they resulted to "unresolved externals" errors!!
[/quote] -
If a library is to be created using Qt, is C++ mandatory to be used or we can use C ?? As the APIs have been written in C.
[quote author="koahnig" date="1370595338"]
I am not sure if understand correctly, but apparently you should familiarize yourself a bit with C++ and OOP. Plain C cannot be combined with Qt libs. At least some of C++ frame work is required. However, most for number crunching and other stuff may be certainly in plain C.
[quote author="deepak_" date="1370595338"]
So, you mean if a library is created with Qt, C++ is the language to be used??
Koahnig, I am familiar with C++ and OOP concepts. Just asked because I have worked more with C and driver as well as APIs are in C.
[/quote]
-
-
[quote author="deepak_" date="1370599663"]
- How about building a library file using Visual Studio and using it?? Some links suggest using “dll” rather than “lib” files. Which is better??
[/quote]
If you want to handle only one exe it is certainly better to use static libs.
IMHO, otherwise there is no difference. Also it does not matter on the compiler used on windows. For your own source part you are free in decision anyway.
IFAIK also when you have a license you have to create the static libs of Qt yourself.[quote author="deepak_" date="1370599663"]
2) Is it needed/preferable to build a library with a GCC compiler for using with a Qt application because Qt Build also uses GCC??
[/quote]
If you have installed MinGW (GCC) version you need to use MinGW for your app as well. You cannot mix different MinGW versions nor can you mix with MS VC versions. You to stick also with the compiler and the respective version.
Other than that you are free. I have used MS VC before. Currently, I use MinGW.[quote author="deepak_" date="1370595338"]
"you are bound to the supported compilers during the pre-build process". What do you mean by "pre-build process??" Is it pre-build for library??
[/quote]
The different possibilities you can download from the download page. They contain already the pre-compiled Qt libs. In contrast to the Qt library source which you have to compile yourself.[quote author="deepak_" date="1370595338"]
3) How to call the functions encapsulated in the library in the Qt application source code?? I could not find a proper way of calling a library function in the application code.. Please refer a link or basic syntax enough to understand the implementation.I tried a couple of methods available on internet but they resulted to "unresolved externals" errors!!
[/quote]When you try to access methods of an object other than the implemented static functions, this would be normal.
[quote author="deepak_" date="1370595338"]
So, you mean if a library is created with Qt, C++ is the language to be used??
Koahnig, I am familiar with C++ and OOP concepts. Just asked because I have worked more with C and driver as well as APIs are in C.
[/quote]
I am certainly not an expert on programming languages, but C++ is an extension of C.
If you like to use the features of C++ implemented in Qt libs, you need in my opinion C++. However, you could limit yourself to the absolute necessary stuff of C++ on your side. Qt libs has only a few static methods and I do not see the possibility to interface through simple C and having the full potential of Qt libs. - How about building a library file using Visual Studio and using it?? Some links suggest using “dll” rather than “lib” files. Which is better??