Using .pri files in Qt - 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.

Related

Qt lupdate in .pro file issue

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)

Proper (tree) display of Qt project using .pro and .pri in QtCreator

Is it possible to display more then only one extra level using project include files (.pri).
For example if .pro file includes .pri file which includes two .pri files.
.pro
.pri
.pri
.pri
In QtCreator (Projects) display is misleading:
.pro
.pri
.pri
.pri
It simply doesn't respect where the .pri file is in the file system and displays them as a at the same .pro level. Or am I doing something wrong or just expecting to much? I am using Qt 4.7.4 and QtCreator 2.2.1.
Starting from Qt Creator 3.6 nested .pri files are shown in a tree. You can check this bug report which is resolved.
Seems like there is some kind of workaround if you ignore the second level of .pri files and just use a new directory and move all includes to root .pri file. For example:
.pro
.pri
new dir A (instead of another .pri)
new dir B (instead of another .pri)
QtCreator (Projects) display:
.pro
.pri
Headers
new dir A
new dir B
Sources
new dir A
new dir B
Good thing about it is that you get to keep the same file structure. I am still hoping they implement detection of new level(s) of .pri. But please let me know if you find out something more that I heaven't.

Qt: *.pro vs *.pri

What is the difference between *.pro and *.pri configuration files for qmake?
What should go into a *.pro file and what should go into a *.pri file?
There is one main difference between their targetted reuse:
.pro
This is usually called Project File.
.pri
This is usually called Project Include File.
As you can see in their names, the main difference is that .pri files are meant to be include files. That is similar to including modules in programming language to share the functionality, essentially.
You will be able to write the common settings and code into those .pri files and include them from several .pro files as the need arises. This is how you would use it in practice:
foo.pri
FOO = BAR
hello.pro
...
include($$PWD/foo.pri)
...
world.pro
...
include($$PWD/foo.pri)
...
This way, the commonality would be available both in hello.pro as well as world.pro. It does not make much of difference in this scenario, but when the shared functionality gets longer, it will save you some writing as well as sync'ing, bugfixing, and so on.
You could even include a .pri file inside another .pri file if you wish. You could also include .pri files in different subprojects, etc. It is very nice.
The syntax is the same, however, for both the .pro and .pri files. In the end, you would run qmake on the .pro files, and that is also what qmake generates for you if you do not have a project file existing and you intend to use qmake -project.
You can read more about the include function in here:
include(filename)
Includes the contents of the file specified by filename into the current project at the point where it is included. This function succeeds if filename is included; otherwise it fails. The included file is processed immediately.
You can check whether the file was included by using this function as the condition for a scope.
Just to be complete, there are also .prf Project Feature Files and .prl Project Linker Files, but as an end user, you do not need to deal with that for now.
A .pro file is what you would run QMake on. A .pri file is included by a .pro file. Other than that there is not much of a difference between the two.
Example usage could be if you have different builds which need different options. You could put shared information in the .pro, while deferring the options to various .pri files. A bit more information, although admittedly not much more, can be found here.
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.
For Reference: *.pro vs *.pri

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.

How to convert .ui(user interface) files into .exe file in QT

I am a fresher in qt,i don't have much knowledge on qt, but i created some of file in qt for my application (regaurding to GUI format).I was created some .ui files in qt,but i wanted these files into .exe format.I think u had unerstand my problem,so please help me
uic (sometimes installed as uic-4) takes the .ui files and generates a C++ header file that you can inherit from. There are a few different ways you can work with the .ui files. See the manual for more information. Feel free to come back with specific questions.
Hallo Ram,
I think you are asking about the inclusion of .ui files within your .exe file.
If I am not wrong, then you need to include you .ui file within your projects specific resource file. It will be usually named .qrc in Qt projects.
The contents of .qrc file will look something like this:
<RCC>
<qresource prefix="/ui">
<file>ui/command/spiwidget.ui</file>
<file>ui/command/SPIMicroCommandWidget.ui</file>
<file>ui/command/utility/externdatawidget.ui</file>
<file>ui/sequencerwidget.ui</file>
<file>ui/command/watchdogwidget.ui</file>
<file>ui/command/utility/repdatawidget.ui</file>
<file>ui/command/core.png</file>
<file>ui/command/LastOpenedFiles.ui</file>
</qresource>
</RCC>
In the code above, you can see the inclusions for .ui and .png(image file) too.
After including it in .qrc file, you can use this resource in your .cpp code as follows:
QFile file(":ui/ui/command/LastOpenedFiles.ui");
Where :ui/ui/command is the path of to the .ui file being used.
Hope this explanation is useful to you!
Try using QtCreator (official IDE for Qt development). One way to use your *.ui file would bet to:
create *.h and *.cpp files containing a class that will load your widget structure.
add your new files to qt project file - *.pro
If your haven't used Qt Creator yet, then I suggest try it.
Create new project (ctrl+n) - Qt C++ Project / Qt Gui Application
Add new form to your project (ctrl+n) - Qt / Qt Designer Form Class
Look at files that where created by IDE. There is *.h file, *.cpp file and *.ui file.
Look into *.pro file, there are 3 sections SOURCES, HEADERS, FORMS
Here are some learning materials:
http://qt.nokia.com/services-partners/qt-in-education/qt-in-education-course-material

Resources