How to create logical directory in Qt Creator? - c++

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 :)

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.

Qt specifying a location for certain application data

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.

Project files in KDevelop

I am trying to use KDevelop to write a cmake based simple application. KDevelop created two myProject.kdev4 project files: one in the project folder and one in .kdev4 hidden subfolder. Both are non-empty. Which ones should I check in? How can I make kdevelop use just one project file (and preferably not use hidden folders)?
The .kdev4 file is used for kdevelop specific information (It mainly only tells KDevelop to use the CMake project manager). The folder includes user specific configuration (If you are familiar with Visual Studio, it is like the .user files).
Usually only the CMakeLists.txt files are needed as they should have all the relevant generic data. You can throw in the .kdev4 file so that you don't need to 'import' the project through the CMakeLists.txt on another machine. But the .kdev4 folder should stay in your local machine, as you don't want to mix user's configurations.

Creating a good directory structure

This might be a silly question but I am still learning. I have read several books on creating application and creating a good directory structure. When people talk about creating a directory structure, do they mean the folders you make within the solution explorer (folders you actually find inside of a .sln file) or do they mean setting up and creating folders that reside in the same folder as your .sln file or your compiled application (.exe). I figured the solution explorer folders are different from a typical windows folder cause the folders I create inside my .sln file are no where to be found on my windows system.
Visual Studio has a strange way of dealing with "folders" in solutions. A "Solution Folder" is not actually a physical folder, but more of a virtual folder managed by Visual Studio. Your files may end up in the root directoy, but VS will treat them as if they are in a "folder." This is configured and managed in the VS .sln or project file.
I'm not a fan of how this works in Visual Studio, I don't get why they don't just put files in physical folders. It's up to you whether you want to fight VS and try to keep your files in physical folders, or if you want to just let VS manage it, but ultimately, it really doesn't matter.
a typical directory struction will be like
bin (binaries)
Src
->.sln
->common
->.prj
->Project1
->.prj
->Project2
->.prj
Lib (3rd party lib's)
Doc (documentation)
Tools (3rd party tools)
Setup (setup projects)
Test (test cases)
With C++ in Visual Studio your solution directories need not match the filesystem, but they can.
Typically people refer to the directory structure as the filesystem layout of the project.
It's typical to have visual studio directories called headers and source, you wouldn't lay your project out like this on your filesystem though.
Visual Studio directories aren't just virtual folders though, they can contain filter rules so when you add a file to your project it will automatically get added to the correct filtered folder. They can also specify whether the folder should be under version control or not. And whether they should be parsed for auto complete or not.
Typically on filesystem I will create 1 folder per project and rarely create subfolders inside an individual project. But in the solution explorer I will create top level folders which I put projects into (For example: "Server Components" and "Client Components"), as well as in project folders to group things logically together (For example: Config, GUI, Controllers, ...) so I can find what i'm looking for faster.

Eclipse CDT: Import source / header files into my new project, without duplicating them

Im sure there is a very simple solution for this.
I have a bunch of .cpp / .h files from a project, say in directory ~/files
On the other hand, I want to create a c++ project using eclipse to work on those files, so I put my workspace on ~/wherever. Then I create a c++ project: ~/wherever/project, and include the source files (located in /~files).
The problem i'm having is that files are now duplicated in ~/wherever/project, and I would like to avoid that, specially so I know which copy of the file to commit.
Is this possible? Im sure it is, but cant get it.
Thanks in advance.
You could try:
creating the project directly above the ~/files (which is not very clean, given the location of the sources in your home dir)
using a linked folder
importing existing sources in your project: details all the options (when your sources are also managed by a VCS like CVS, or when your sources are not managed)
Create a file or folder in your project as per normal (choose File->New->Folder), give it a name, and click on the Advanced button. This reveals a file-choose field where you can browse for the resource you want to "virtually" include in the project. Click Okay and the file/folder you named is now linked outside of the project.