When writing plugin libraries with Qt one can attach a JSON file containing some meta data to it using the Q_PLUGIN_METADATA macro. This JSON file is then linked into the library, for later usage with QPluginLoader::metaData().
Unfortunately when building the plugin library the associated JSON file is not by default seen as a dependency for the library binary by qmake. When the JSON file is modified the plugin library project has to be rebuild (especially re-linked) manually to force the modified JSON file into the library binary.
What would be the proper way to mention the JSON file in the .pro file so that it is automatically linked in when it is modified?
I typically use the following to make the json file a dependency of the generated moc file that contains the corresponding code. Assuming the class where you specify Q_PLUGIN_METADATA is located in a header file called myclass.h, the qmake code is as follows:
DISTFILES += myclass.json
json_target.target = moc_myclass.o
json_target.depends += $$PWD/myclass.json
QMAKE_EXTRA_TARGETS += json_target
Note: You might have to use json_target.target = $$OBJECTS_DIR/moc_myclass.o instead, if OBJECTS_DIR has previously been defined. Check the generated Makefile to see if the path of the dependency matches the one of the corresponding target.
Well, you could just add the JSON file to resources: create some *.qrc file, add yours there and then write in the .pro file something like RESOURCES += plugin_data.qrc.-
There is also DISTFILES variable, but AFAIK it's Unix-only and does not solve your problem.
Tried myself and it never worked, still the recipe from documentation works: INCLUDEPATH += JSON_FILE_LOCATION_DIR. It's true that qmake caches builds sometimes, but they say adding to include path should do the trick and make a proper build.
Related
I know it is a topic already touched by a lot of user, but I don't find a valid solution; I have two form files created with QtDesigner:
interfaccia_test.ui
interfaccia.ui
I launch qmake -project command obtaing the following .pro file:
TEMPLATE = app
TARGET = qtgeo
INCLUDEPATH += . include
# Input
HEADERS += interfaccia.h include/localizzazione.hpp
FORMS += interfaccia.ui interfaccia_test.ui
SOURCES += interfaccia.cpp main.cpp src/localizzazione.cpp
src/SimpleSIFT.cpp
so i give qmake command but it doesn't generate ui_interfaccia.h and ui_interfaccia_test.h like I expected; then I try to make my project and I have
interfaccia.h:19:28: fatal error: ui_interfaccia.h: File o directory not found
#include "ui_interfaccia.h"
^
with interfaccia.h my file that use the GUI I made.
For any given project, you should ever only use qmake -project once. It's meant as a starting point if you have a bunch of files and want to get a project template. This template is then meant to be modified by a human being - you.
The normal way to build a qmake-based Qt project would be:
qmake
make
The ui_xxx.h files are generated by make, not qmake. Here's a list of what the various tools do:
qmake -project Generates a .pro file template for you to modify to suit the project. This should never be used by your end users, or by you after the project is going. It's your job to keep the .pro file up-to-date.
qmake or cmake Generates the makefile for the build system.
make or ninja Builds the project, generating all the other files.
There are two additional points:
The qmake won't generate the ui_xxx.h file if you've included a file that wouldn't be generated. So, for example, if it'd generate a file called ui_Interfaccia.h, but you've included ui_interfaccia.h, then the file with the wrong name nor the file with the correct name get generated.
This matters even if you're building everything on a case-insensitive OS/filesystem.
You're including the file with a wrong name. The correct name is ui_ClassName.h, where ClassName is the name of the class from the .ui file (look at the first few lines), with the same capitalization.
I'm using the qt4 tool for scons and having some troubles getting the .ui files to be handled correctly. I'm coming from a Cmake background with Qt and a beginner with scons.
In my SConstruct file I have
env.Uic4(Glob('*.ui'))
env.Program('test',Glob('*.cpp'))
The problem is that my source file can't find the resulting header files src/qt-test/sample_widget.cpp:3:23: error: ui_sample.h: No such file or directory. The header file is created, as is all moc processing done, thus I'm pretty sure everything is installed correctly and basically correct.
What I think is happening is because this is a recrusive SConstruct file, and the caller is using a variant_dir for the build. So possibly the problem is just getting the compiler to resolve headers in the build directory (and perhaps nothing to do with the qt4 tool). This was handled automatically in CMake (I think).
So how do I get this working (get the ui include file to be found)?
Use the CPPPATH construction variable to set the include paths as mentioned in the man pages:
http://scons.org/doc/production/HTML/scons-user/a4916.html
For example:
env.Append(CPPPATH = ['dir1', 'dir2'])
Brady
I'm getting the error
QAction: No such file or directory
when I try to compile a project for plugin (C++ Library template). Weird, because I have a project for my app which also includes this header and there is no error. What might cause this?
For me I had some stale moc_ and ui_ files left over from compiling under a different version and configuration of Qt, so removing them solved the problem for me.
rm moc_* ui_* *.o
Make sure that you have the right include paths set up.
If you use QMake the *.pro should contain these settings if you want to include files from QtGui. They should be set by default but some templates may not set them.
CONFIG += qt
QT += gui
If you use another build system then make sure that you either use
#include <QtGui/QAction>
or you add $QTDIR/include/QtGui and not just $QTDIR/include to your include path
I have been told that it is possible to generate a pkg-config file through qmake, but I have no idea how to do it. I have been looking online for a while, and it seems as though it is something you just have to know how to do. Can someone give me an example, or point me to some sort of guide/tutorial?
If you want to generate a .pc file (in contrast to simply use pkg-config to find dependencies, which is well supported by qmake), you might be interested in the following. Obviously, creating .pc files is a less visible, but existing feature of QMake. You want to use CONFIG += create_pc, which depends on create_prl. If you don't want to install the .prl file, use no_install_prl, too. Overall, this gives you:
CONFIG += create_pc create_prl no_install_prl
QMAKE_PKGCONFIG_NAME = VigraQt
QMAKE_PKGCONFIG_DESCRIPTION = Qt4 bindings for the VIGRA library
QMAKE_PKGCONFIG_PREFIX = $$INSTALLBASE
QMAKE_PKGCONFIG_LIBDIR = $$target.path
QMAKE_PKGCONFIG_INCDIR = $$headers.path
QMAKE_PKGCONFIG_VERSION = $$VERSION
This is what I came up with for VigraQt. There's also QMAKE_PKGCONFIG_DESTDIR, which you may use to specify the location of the .pc files within the source directory. Finally, there are QMAKE_PKGCONFIG_VARIABLES, QMAKE_PKGCONFIG_REQUIRES, and QMAKE_PKGCONFIG_CFLAGS in addition to the above.
(There is also create_libtool for .la files, which also depends on the .prl files.)
Is this what you are looking for?
To generate pkg-config using qmake you have to add to (modify) your project file (*.pro file):
unix {
CONFIG += link_pkgconfig
PKGCONFIG += <pc_file_without_extension>
}
Hee,
I'm kinda new to Qt and i started to add UnitTests to my Qt project. Qt demands that i put my unit tests in another project, so i did.
But now i have dependent source files in my first project. I made my 'main project' a dependency of my 'test project'.
I cannot seem to include any of the '.h' files from my 'main project'. The unit test them self run properly as long as i do not use classes from my 'main project'.
I looked into the Qt documentation, but i cannot find the solution for my problem. Am i missing something?
Did you try to include your dependencies to .pro file of your test project?
HEADERS += ../MyHeader.h
SOURCES += ../MyHeader.cpp \
tst_myUnitTestName.cpp
You can try adding the path of your main program in the includes (in the testProject.pro file)
INCLUDEPATH += .. .
(or just add the path to the project itself)
if you do this, you will then need to change your includes (in the .cpp files) from "" to <>
#include < MyHeader.h >
Adding the headers to the .pro file will mostly allow you to have easy access to the file itself if you're using QtCreator (and qmake will complain if it doesn't find the files), but it will not solve the actual dependencies within each .cpp file.