Qt specifying a location for certain application data - c++

I am making an application in Qt. I have 2 directories, 1 for configurations, the other for program scripts.
I would like to have it say that when I build the project, it will place those directories in a certain directory.
For instance on linux:
/home/username/.project_name/configurations
/home/username/.project_name/scripts
This should also be cross platform, so on Windows and MacOS these files should be placed in the normal place where application data is stored.
Is there there a way to specify where these directories (and the files in them) should be placed? Is it an option in the project file? And which option ?

The qt resource system is used to store files within your application's executable.
You need to answer two questions:
Where do the files come from? Does your installer or package contain them, or are they in the executable proper and the application extracts them and saves them. Then the qt resource system is useful.
How to get the path you need to create your configuration directory. QDesktopServices::storageLocation(QDesktopServices::DataLocation) returns such a path in a cross-platform manner.

Related

Setting up C++ include settings for a large library such as Paraview and QT in Eclipse

I have an application where I am compiling against the libraries Qt (5.11) and Paraview (5.6). I am developing in C++ and I am also coding in Eclipse.
Yes, I am aware that Paraview is more of an application then a library. However, I will be using it as a library to intergrate Paraview in my application in order to visualize some data. I could use QT creator and that would take care of the QT library. However, I am not very familiar with QT creator as an IDE and my entire workflow has been based around eclipse. For this, I would like to utilize components that I am familiar with.
Now, as many of you know, the QT library is large, very large. So is Paraview. I could create a search path for each folder containing the header files I need in the C++ include settings. If I go in this direction, then my library search path will be long, very long. Also, there might be a situation where I need to change computers (for whatever reason), I would then need to edit the search paths for the new computer and that will take time.I had thought that I could only include the paths to the include files that I needed. And I have started to do that. However, when I compile my application, I noticed that the libraries would use include files that are located in a directory that Eclipse is not even searching in. At the end of the day, I would need to include all of the directories to which the header files are stored in.
I was wondering if there might be a better method to reference all of the files that my project needs? Both come with make files (I believe that Qt includes a QMake file?). Is there a simpler method to include all of the files instead of editing the C++ include path for eclipse? I did see an option for QMake in Eclipse, is there anything that I can do with that feature to compile to QT library with my application?
Thank you and any feedback is appreciated. Also, feel free to suggest edits or clarification so that my description is clear.
Note some good practices when working with eclipse and qt or other large library.
Include the directories with a headers
If you use option "Generate Makefile automatically", add group include path with GUI Eclipse:
copy the directories with a headers (via system explorer);
go to project properties/C/C++Build/Settings/Tool Settings/GCC C++
Compiler/Includes.
paste directories (Ctrl+V) into "Include paths" list.
If you are using a qt-eclipse-integration plugin, you can add folders via the Discovered scanner configuration. You can find it if open: project properties/C/C++ Include Paths and Symbols/Add Contributed...
Create new project
if you already have a customized project, you can use it as a template:
make a copy of the customized project and name "mytempate";
delete all files from "mytempate".
When you want to create a new project, copy the template and specify (in the copy dialog) the path where the source codes are located.
Now you have a finished new project with settings and code.
Change computers
Use one of the ways:
1. Export C/C++ project settings for use in another workspace via project properties/C/C++ General/Paths and symbols/Includes/Export Settings...
2. Pack in the archive eclipse and workspace and copy your another computer.

C++ Moving DLL out of root directory into a subfolder, visual studio

I'm a beginner with building software using C++. In my project I link to DLLs and I keep them stored in the root folder. I do this because I want the project to be portable from one machine to another, and I also want the release builds to have dependence from installing things into system32 and what not.
The problem is all the DLLs in the root folder is messy, so I want to organize them into subfolders. But I can't do that because putting the DLL in a root subfolder instead of the root, you get errors. I think because the DLL is copied to the output at the wrong location, not where the exe is, but in a subfolder, just like the source structure. Am I right about that?
What is a solution that will allow me to have the project be still be copy-pastable/portable between machines?
Windows searches for DLLs in predefined locations (see Dynamic-Link Library Search Order). Subdirectories of the directory where the application resides are not part of the search order.
To implement your requirement, you will need to explicitly add the directories to the searched locations. This process consists of two steps:
Call AddDllDirectory for each directory you want searched, in addition to the default search locations on application startup.
By default, DLL imports are resolved prior to starting a process' primary thread. To allow your application to change the DLL search path, import resolution needs to be postponed. The easiest way to do this is by using the /DELAYLOAD (Delay Load Import) linker option (see Linker Support for Delay-Loaded DLLs for additional information).
While it is possible, to segregate DLLs into subdirectories, it is best to keep them all alongside the executable image.
If you put the DLLs into subfolders instead of keeping them in the same directory as the executable, you would either have to modify PATH environment variable in Windows to point to every subfolder, or use the DLLs in LoadLibrary+GetProcAddress way instead of linking them to the executable via import libs.

Set QT base directory through system variable

I've compiled QT and copied it over to a network drive. But now I've got the problem that the platform plugins are only found on my computer because it seems that those path got compiled into the binaries. How can I make QT to look into another directory? I thought that the system variable QTDIR should work but it gets ignored completely. Also tried to add a bunch of directories to the PATH variable which didn't work either.
I need a solution which is useable without changing the code itself.
If you need to load Qt plugins from different path you must use environment variable QT_PLUGIN_PATH.
Qt also looks for the plugins in directories relative to the path where the executable is installed. You need to properly deploy your applications, and you definitely don't need to copy the entirety of Qt anywhere. You also don't need to set QT_PLUGIN_PATH - it's a workaround for a simple problem.
Ideally, as part of your application's release build process you should be creating an installer, and that installer would then handle putting all the plugins into the application's installation folder.

How to create logical directory in Qt Creator?

All my source files are stored in one project (physical) directory. Qt creator shows this files in 3 folders: Headers (for *.hpp and *.h), Sources (for *.cpp and *.c) and Forms (for *.ui). But I would like to have a few another logical folder. For example I would like to create logical folder "protocol" logically containing *.hpp and *.cpp files which maintain network connection and so on. I don't want to create a new folder on my disk for these files. I want only logical one in Qt Creator. Is it possible?
One more reason why I need these logical folders is that I would like to see often used files in one place
QtCreator 3.0 has QBS support, a build system that will supersede qmake.
It has Group of files, which is displayed as a virtual folder.
Anyway, having too much files in one folder is always annoying and a bad practice.
By using prefix property of Group you can easily change the path of files.
For qmake projects, the only way it's possible, unfortunately, is by tweaking Qt Creator project manager plugin sources.
Remember that Qt Creator doesn't manage any of those files by itself. The file lists are extracted from project file(s) by a project manager plugin. If/when a plugin adds them, they are added to the project file(s).
You're most likely using the qmake project manager. A "simple" way to do it would be to extract the file grouping from variables with a common prefix. Let's say the intersection of each QTC_Foo with union of HEADERS and SOURCES would be displayed in Foo group.
I think it might be simple to implement, so I might come up with a patch later in this answer. The first step for you is downloading and compiling Qt Creator :)

Xcode Copy Files Build Phase - what do the "Destination" options mean?

The Xcode docs for this don't explain exactly where each of the Destination paths maps to on disc, relative to my application package.
If I use this app as an example, could someone give a canonical answer where each will put files relative to this directory structure?
The app bundle in your example is Viewer. This is not a file; it's a directory. If you click on it and "Show Package Contents", you'll see the rest of it.
Products Directory is the directory that Viewer is written to. You cannot write to this directory in iOS.
For iOS, Wrapper is the top level directory within Viewer.
For iOS, Executable is the same directory as Wrapper.
For iOS, Resources go into either the Wrapper directory, or the localization directories (Base.lproj, etc) if the resource is localized.
The other directories aren't meaningful for iOS.
Still, you should use the directories logically. Use "Executable" to mean "the directory where my executable lives." Don't assume that the directory tree is laid out a particular way internally.
Regarding your comment that you need to know the path to access the file, you do not need that (and shouldn't try). You should use [NSBundle pathForResource:ofType:] to find files.