Qt lupdate in .pro file issue - qt

I had to mark some of the .xml files for internationalization. I do not use lupdate manually from cmd, instead I put it in the project's .pro file like:
lupdate_only{
SOURCES += $$EXTRA_XML
}
The above code works just fine, but as you noticed I had to put the xml files in SOURCES. As a consequence the .xml files appear in the Sources virtual folder from the left Projects' perspective window, just next to the .cpp files. I find this solution a bit nasty and confusing.
- Project
- - Headers
- - Sources
- - - main.cpp
- - - some.xml //not wanted here
Is there a way to use lupdate, in .pro, on different files such that those files won't appear in the Sources folder? Thanks!
UPDATE
I use Qt Creator 4.0.3

lupdate_only {
SOURCES += $$EXTRA_XML
}
With this conditional statement, lupdate tool sees the .qml files but qmake will ignore it.

I found the solution to my problem, however I think it's a Qt Creator bug. I just moved the lupdate statement with its contents into a .pri file and now the xml files do not appear under the Sources virtual folder. (the .pri file is included in .pro)

Related

Set Additional Include Directories in Qt Creator

I am using Qt Creator to rewrite my former project which is developed in Visual Studio. In this project I need to use an external library (gloox for xmpp).
Here's what I did in Visual Studio:
Add c:/dir1/ to the Additional Include Directories, that's where the tons of .h and .cpp files are.
Add c:/dir2/ in the linker setting, that's where the .lib file is.
I want to do the same thing in Qt Creator, so I added INCLUDEPATH += c:/dir1/ to the end of my .pro file, but when I qmaked again I still could not include anything from dir1 successfully.
#include <message.h>
C1083: Cannot open include file: 'message.h': No such file or directory
What should I do?
Based on the comment discussion, the problem seems to be that, after the INCLUDEPATH and potentially other relevant modifications, you forgot to properly re-run qmake.
This is necessary when dealing with QtCreator unfortunately due to the following long-standing issue:
Creator should know when to rerun qmake
I found the solution: copy everything in the .pro file and delete the .pro file. Then create a new .pro file and copy everything back, then execute qmake then run.

Qt: mingw compiled library does only work with both library.so and library.lib file present

I compiled a library using the MinGW toolchain provided with Qt 5.0.2 on Windows. As a result I received a library.so file. First I failed using the library in a Qt application, but now I found out that everything works fine when I make a copy of the liblibrary.so file and call it liblibrary.dll or liblibrary.lib (which is the only file ending supported by the add library wizard in QtCreator).
Now I wonder if this is normal or if I should change something in order not to have both files (which are exact copies). Leaving one away makes the application crash during start up. I added the library as follows to my Qt pro file:
LIBS += -L"../path/to/library" -llibrary
INCLUDEPATH += $$quote(../path/to/library)
EDIT: I compiled the library using the MinGW of Qt, not as Qt project but using mingw32-make and the provided Makefile. As a result I get the liblibrary.so.
EDIT: It seems to work also when renaming the copy to liblibrary.dll instead of .lib. But still, I need two files to make the application work -- the .so and the .dll.
Chris
That's weird, I think you should get a *.a and *.dll files when building a shared lib with MinGW on Windows, as said in the documentation:
In windows, MinGW will output .a and .dll, MSVC2010 will ouput .lib and .dll. In linux, MinGW will output .so, .so.1, .so.1.0 and .so.1.0.0 – .lib, .a and .so are import libraries.
You definitely shouldn't rename your file!
Be careful to:
not to include the "lib" prefix after "-l" in your project file.
put everything after after "-l" in lower case as you're on Windows
not adding any extension to your library name after "-l"
add and reference the .h file used in your library
A real example using QtWebsocket lib:
INCLUDEPATH += "$${PWD}/include/"
LIBS += -L"$${PWD}/libs/" -lqtwebsocket
...
HEADERS += ... \
$${PWD}/include/QWsSocket.h \
...
In my include/ folder, I have the following file:
QWsSocket.h (taken from original project - required)
In my libs/ folder, I have the following file:
libQtWebsocket.a
QtWebsocket.dll
Edit: I struggled with this too initially. Have you tried to build your lib as a static lib instead (CONFIG += staticlib in your library project)? This might help you getting you *.pro file right before switching to using the shared library.
Edit 2: Ok, the fact that you get a *.so file is still a bit odd. In this question
the user has the same issue as you and keep both files, which is just a workaround. According to a later answer it seems that you need to modify your makefile to generate a file with the proper extension. Maybe this will help: http://www.mingw.org/wiki/sampleDLL

How do I add an entire directory to a QT creator project

I have an existing QT Creator project. I want to add an entire directory to this project. I see that I can right click in the project file browser tree and "Add Existing Files..." However through this dialog box, I can only add individual files. How can I include an entire directory?
The simplest way is to directly edit your .pro file, add HEADERS += mydir/*.h and SOURCES += mydir/*.cpp and the contents of the whole directory will show up in QT Creator. Further reference: http://qt-project.org/doc/qt-5/qmake-project-files.html
Open a terminal, navigate to the folder where you want to have you project file, and then run the command
qmake -project
This will search the current directory and all subdirectories for files with extensions such as .c, .cpp, .h, etc. (the full list is found by typing man qmake).
But keep in mind that it will overwrite your current .pro file if you already have a project set up.
qmake provides a convenient files function for this very purpose. Adding the following line to your project file will add .cpp files inside the src/ directory:
SOURCES += $$files(src/*.cpp)
By default, this is non-recursive. Setting the second parameter to true recursively finds all files:
SOURCES += $$files(src/*.cpp, true)
The files function was introduced since Qt 5.10.
Nowadays you can just right click on project name and select Add existing directory

Does the qmake includes pri files automatically in the pro file

Assume the following directory structure
project/project.pro
project/project.pri
In this case even if the project.pro file does not have a statement like (include project.pri). Does it gets included automatically by qmake.
In the qtcreator sources plugin directory
qt-creator/src/plugins/coreplugin
There is a coreplugin.pri file which is not included in the coreplugin.pro file
I'm fairly confident that it does not get included automatically, and I did a quick test with a .pro and a .pri file that had message calls in them to confirm this.
With regards to the files you're seeing in creator, it's not uncommon to have a .pri file that is designed for other .pro files to include so that you can use the project.

Using .pri files in Qt

This is a followup to this question How to create a subdirectory for a project in qt-creator?, where the first answer didn't work for me.
I resolved it by manually writing every file into the main .pro file, which is not that much harder, but I still wonder - how exactly .pri files work, and why the solution linked above didn't add the folders, but only the .pri files, so it looked like this in Qt creator:
So, my questions are:
What is the general format of the .pri files?
Why the solution above doesn't work?
The format of the .pri files is exactly the same as the format of the .pro files. The main difference is one of intent; a .pro is what most people would expect to run qmake on directly, while a .pri is to be included by a .pro. When you instruct qmake to include another file, it just processes the commands in that file as if it were in the current file.
The last time I looked at Qt Creator, it would do additional parsing and recognize that .pri files were separate, and list any headers/sources/ui/rc/pri files from that file specifically as a subdirectory, much like you see the include.pri files listed in the screenshot of this question.
My guess from looking at your screenshot is that QtCreator doesn't find the header files listed in the .pri file. If your .pri file is located in a different directory than your .pro file (which seems to be the case here), Qt looks for the files listed in the .pri file in the same directory as the .pri file (not the .pro file), and any relative path will be resolved from that directory.
When a file can't be found, QtCreator silently ignores it and simply doesn't add it to the folder in the projects view. If, for example, you used the full path for line.h, circle.h and bezier.h in your include.pri file, as soon as you save the file, you'll see them appear in the projects view. The key now is simply to figure out what is the appropriate relative path pointing to those files relative to the .pri file.
Extracted from Qt 4.5: Managing Projects:
The .pri file contains the list of source files, header files, .ui files, and .qrc files in the project.
For more about these files and their OSs:
A .vcproj file containing Windows-specific settings and listing the files in the project.
A .pro file containing Unix and/or Mac OS X specific settings.
A .pri file (a qmake include file) listing the files in the project.
I suggest you to take a look on the link.

Resources