I have a custom library to be included in Qt. Currently, it is included by adding the followings in .pro file.
INCLUDEPATH += ...
DEPENDPATH += ...
LIB += ...
Since the library is used in most of my projects. I am wondering that if there is some way to make my custom library to be INTEGRATED with the QtSDK? Maybe it can be included by syntax like the build-in components
QT += my_custom_library
and everything (header file include path, lib file include, etc...) will be done.
Is the integration possible?
You are probably looking for to create a mkspec file which then used with CONFIG option. So create a file to $QT_HOME/mkspec/features/mycoollib.prf that contains your instructions. There should be plenty of examples in that directory. The name of the file declares it's usage, so the file mycoollib.prf would be used like:
CONFIG += mycoollib
Related
I have small frequently modified *.pri source-libraries, purpose of those pri's is to add headers and sources, do aux tasks like copy file. Those libraries are at same or higher directory level than the project that will use them and must have access to parent project variables (e.g ANDROID_PACKAGE_SOURCE_DIR)
example of *.pri:
#AnFeature/AnFeature.pri
HEADERS += $$PWD/anfeature.h
SOURCES += $$PWD/anfeature.cpp
INCLUDEPATH += $$PWD
OTHER_FILES += $$PWD/android/src/example/anfeature/anfeature.java
QMAKE_POST_LINK += $$QMAKE_COPY_DIR $$shell_path($$PWD/android/src/example/anfeature) $$shell_path($$ANDROID_PACKAGE_SOURCE_DIR/src/example/anfeature)
Looking how to implement that kind of stuff via CMake 3.19 or newer
HEADERS and SOURCES are just variables, so you can use target_sources. You can even set the source property on targets using set_property.
For INCLUDEPATH, you can use target_include_directories. Or simple specifying your library dependency after finding it with find_package using target_link_libraries
For OTHER_FILES, you can just again set a cmake variable if you really need to.
For running custom commands, like QMAKE_POST_LINK does, you can use add_custom_command.
I have a project in Qt Creator which has several shared library projects and the main project which also contains the main function. What I want is to add a new project which shouldn't be a shared library but just a project with some header files where I keep definitions and error codes. What I wish is to be able to add the path of this project to other projects INCLUDEPATH in order to use those files in other projects.
To do so I created an empty project which .pro file looks like this:
HEADERS += \
myHeader.h
but when I build the whole project it complains that it doesn't find the main in this project with only one header.
Is it possible in QtCreator to achieve this?
Create a .pri file which has your INCLUDEPATH, etc; and then refer to it in your other projects' .pro files:
# Common.pri
INCLUDEPATH += ../myPath
INCLUDE += myHeader.h
# OtherProject.pro
!include( ./Common.pri ) {
error( Could not find the Common.pri file. )
}
INCLUDEPATH += ../myOtherPath
Remember to use the += operator in your .pro files otherwise they will overwrite the .pri file variables.
I have a project that uses Qt. So I have "qmake" make my Makefile from the .pro file. But Qmake can also make that .pro file: qmake -project . This worked until I needed to add an external extra library to my project.
I get lots of hits on google that tell me to add LIBS += ... to my project file, but I want to tell qmake -project something that causes it to add it for me. In effect of course I'll be doing it myself, but I don't think that it's proper that I am editing the generated project file.
If for example I add files to the project directory, I'll have to recreate it and add in the library again, or I'll have to manually add the files to the (almost completely computer-generated) project file. I'm now using a script to auto-generate the project file, and then add in the LIBS += directive, but is there a proper way to do this?
When you are developing without the Qt Creator IDE, unless the IDE includes by itself some automatic utilities, you must edit manually the .pro configuration file.
The generated .pro file is a skeleton file which YOU must fill in with the libraries that you need, then the qmake system figures out the other dependencies and compiles your project. It is a essentially a much better version of pkg-config of gtk + Makefiles.
When you add more source and resource files to your project then manually you must add them to the .pro file.
Example:
QT += core gui
TARGET = qtcp1
TEMPLATE = app
SOURCES += main.cpp\
mainwindow.cpp \
miwidget1.cpp \
lcdrange.cpp
HEADERS += mainwindow.h \
miwidget1.h \
lcdrange.h
FORMS += mainwindow.u
Alternately, you can issue qmake -project over and over again, but this can cause some unforseen accidents, since it includes everything that is in the current directory at the time, including the pre-processed files for conversion to standard C++ from QT dialect. This intermediate files must be erased (cleaned), before the remaking the project and the next make or can lead to tricky problems.
Using the official and free QT Creator IDE takes away most of this burden by adding automatically the new data to the .pro file and cleaning loose ends. Some other IDEs like Code::BLocks and Codelite provide some facilities for QT, but not to the level of QT creator. Some prefer to edit the .pro themselves for custom reasons, other like more other styles of IDEs, like Eclipse.
You should test the waters and decide by yourself what fits best to your needs.
ReEdited, to clarify a few things.
I made a custom library and i compiled it into a dll (qustom.dll).
Now i want to compile another project using this dll.
What i did is to import the header files in the project and add this line in my .pro file
LIBS += -lqustom
but i get "error: cannot find -lqustom"
also i tried
LIBS += qustom.dll
and
LIBS += -libqustom.a
qustom.dll is in the project directory
Also i tried
OTHER_FILES += \
qextserialport1.dll
but didn't work either
Am i missing something here?
Missing a path perhaps? -L/path/to/dlls -ldllname
Qt plays nicely with CMake. I use that and I never get dependency/path headaches like this any more.
I want to use CTelephony API in Qt Symbian project but after including etel3rdparty.h and etel3rdparty.lib as library and header in .pro file like this:
LIBS += C:/NokiaQtSDK/Symbian/SDK/epoc32/release/armv5/lib/etel3rdparty.lib
INCLUDEPATH += C:/NokiaQtSDK/Symbian/SDK/epoc32/include
I am getting a lot of compilation errors.
Please share if someone faced and find the solution of this problem.
You are not supposed to include each library with the complete path in the .pro file. You need only the name of the lib, without the extension, prefixed with -l, i.e. in your case
LIBS += -letel3rdparty
Also, you would normally not need to add epoc32\include to the include path, as it's added by default.