Build directory for Qt Creator IDE - qt

I am trying to populate a QTableview with some data. When developing under Qt Creator, data is read from build directory. Running the program each time, the QTableview keeps getting repopulated with previous data.
If I manually change the build directory each time before run, doesn't happen. But how do I solve the problem without manually changing the build directory every time I want a fresh run?

In your project directory there is a file name ProjectName.pro.user.
This file creating when you configure your project. it's XML file.
you can find this line on *.user files:
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">C:/Users/probook/Documents/Qt/testProject/Build/Windows/Debug</value>
This line define build directory address for debug. there is a same line for Release and Profile in that file.
You can also use Qt creator to define(customize) relative directory build:
goto Qt creator, Tools, Options..., Build & Run, General, Default build directory.
More info:
Qt Creator stores user-specific project settings in a .pro.user file. You can share these settings between several projects as a .pro.shared file. It has the same XML structure as a .pro.user file, but only contains the settings to share.

Based on comment, issue seems to be data which gets saved to build directory. And solution would be to remove it before running the application.
You can add Custom Process Step, either under Projects - Build Settings -
Build Steps, or under Projects - Run Settings - Deployment, and just delete the desired data files. Exact command depends on operating system.
An alternative might be to add a command line switch, something like --development-erase-saved-data, to the application itself, and erase the files (or just not read them, or whatever). Then add that command line switch to Projects - Run Settings - Run Steps - Command Line Arguments for desired build configurations.
Adding support for this in the application itself is easier to maintain, and is almost automatically cross-platform. However, it might be a feature you don't want in the application, though in that case you might only enable it for Debug builds (with #ifdef).
As a side note, saving data to executable directory is not a good idea these days. You might want to save it for example to location returned by
QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)
(See here for more info.)

Related

Ctrl-r do not run when the build directory has been changed

By default the build directory of a project is a sibling, withing the same directory than the project himself.
To have a better organisation in my backup process, I have moved the defaut build path in a directory which is sibling of the parent directory of all my projects. The compilation default path has been updated accordingly.
Now I only backup my projects, without the builds.
The problem I'm facing now is about the execute key combo Ctrl-r for which I get the compilation progress bar, but in fact, the project is not compiled now. This is confirmed because the compiled files do not update within the buid directory.
The only way, now, to update compilation is through the menu Build-> build all. It works but without key binding and I need after to execute.
Is there a way to recover Ctrl-r when changing the build directory path ?
Thanks for help
When you run a project from Qt Creator, it gets rebuilt only if needed, as clearly stated here:
Run configurations start the application in the location where it was
copied by the deploy configuration. By default, when you select the
Run function, Qt Creator builds the project, deploys it to the device
defined in the kit, and runs it there. However, if you have not made
any changes to the project since you last built and deployed it, Qt
Creator simply runs it again.
The only way to force build is to issue the rebuild command explicitely (you can use the Ctrl-B shortcut for that purpose).
If the default build directory is changed (in Tools>Options>Build & Run>General) this setting will apply (as a default) for subsequently created projects. Existing projects will keep their build directory, as specified in the project Build Settings.
You may also want to check if the options
Always build project before deploying it
Always deploy project before running it
in Tools>Options>Build & Run>General are set.
Sometimes, editing a header file does not trigger a build, even if the file is included in some cpp file. To solve this issue in Qt Creator, just add a line like this to the pro file:
DEPENDPATH += path/to/the/header(s)

MAKEFLAGS in Qt Creator via .pro project file

The PC I'm using has 4 cores so I wanna use all them while compiling, which I do by passing the -j4 option to the compiler. In Qt Creator I do that by adding an environment variable in the Build Environment panel, as shown in the images:
MAKEFLAGS = -j4
The problem is that this setting doesn't persist across all projects in the PC I'm using, which will be cool. So I have to do that for each project at least once. I think this is stored in the .pro.user file, since every time .pro.user gets deleted the MAKEFLAGS = -j4 desapears from the Build Environment panel.
Isn't possible to just add this setting via .pro project file?
I'm interested in any approach which will allow me to escape from the necessity of setting that stuff multiple times.
To give a little context, I'm on Windows.
You're looking for shared project settings in a .pro.shared file. They are designed exactly for what you have in mind.
Adding the setting to a .pro file is wrong, since that file is meant to be portable and not tied to any particular build host.

Visual Studio vs version controlling

I have ASP.NET project, which is under Git.
I want to make some small change in aspx file and of course it generates connected change in aspx.Designer.cs file.
However, I want a patch commited to be relevant to change I've made - this is so that I can (for example) do code review without need to skip all automated changes.
Therefore I want to add *.Designer.cs files to .gitignore and regenerate them when updating local workspace (automatically, not file by file).
I've been searching for some command line to compile aspx files but without success.
Could you possibly know some solution to my problem?
For now my environment is Windows+Cygwin.

QWebview examples: only runs in specific directory

I'm trying to create a Qt app with a webview. I started out with a very simple UI with nothing more than a QWebview. When trying ui->webview->SetUrl("http://google.com"); the application crashes on something with openssl.
Auto configuration failed
3348:error:0200107B:system library:fopen:Unknown error:.\crypto\bio\bss_file.c:169:fopen('c:cygwinhomeAdministrateurbuildslavefull-windows_xp_32buildgpac_extra_libs/c:cygwinhomeAdministrateurbuildslavefull-windows_xp_32buildgpac_extra_libs/ssl/openssl.cnf','rb')
3348:error:2006D002:BIO routines:BIO_new_file:system lib:.\crypto\bio\bss_file.c:174:
3348:error:0E078002:configuration file routines:DEF_LOAD:system lib:.\crypto\conf\conf_def.c:199:
I continues trying the examples. Domtraversal is one of the easier applications so i tried to build and run this. It works.
Changed the url to "https://gmail.com" which also works (so no ssl issues there).
When i run the debug or release .exe it works normally (qt's bin path is in my path var so there are no dll problems), but when i move the executable to say, my Desktop it does not run.
I've tried several different things:
when i have any tree with the same amount of folders up to "build-domtraversal-Desktop_Qt_5_0_2_MSVC2010_32bit-Debug" as the folder it is build in continues by release with the executable in it (so: c:/test/test/test/test/test/test/build-domtraversal-Desktop_Qt_5_0_2_MSVC2010_32bit-Debug/release/app.exe) it works
When i add folders inside the release folder (...-Debug/release/test/test/app.exe) it works
When i change the name of either "build-domtraversal-Desktop_Qt_5_0_2_MSVC2010_32bit-*" or release folders it does not work (exept for the end of the build folder name)
When i change the name of the app itself it works.
When i change the folder structure to D:/* it does not work
When i turn off shadow build it does not work anymore in debug mode either. Unless i move the output .exe back into a folder structure where it did work.
There must be a path somewhere in the .pro.user or somewhere else i haven't thought about. Can anyone point me in the right direction? Cause right now I'm starting to believe in magic...

Qt including resource directory structure inside executable

I'm using QWebView to run a web app. There are 650+ files. Placing the web app's directory in the source directory does not result in the executable bundling the directory.
How do I include the entire web app directory so that the executable will be able to render the files.
Note: I have currently added index.html as a resource, and can access it with qrc:// - But since I cannot add the entire directory structure to a qrc (can I?), the executable does not include the other files.
You need to put an XML node into the .qrc file for each file you want to use using the Qt resource system.
This can be done using a simple pre-build script. Take a look at qrcgen. Quoting the blog post behind this link:
The script I created, qrcgen, takes a directory and a prefix, recursively scans the directory and generates a .qrc file with the same name as the directory scanned. It has solved my problem, and I hope it can help others. It is also available via PyPI, just "easy_install qrcgen".
In order to update the .qrc file whenever your directory contens change, you need to include this step into your build process:
For C++/Qt projects, you can add this step in the build configuration in QtCreator or add in your qmake file a system(...) statement. Note that such commands aren't portable in general. (If it's not portable, you can put some operating system conditions around multiple commands.)
For PyQt/PySide projects, I don't know how to do this, but I'm sure you find a solution for this too.

Resources