Organization of projects with qMake

Asked

Viewed 147 times

0

I’m developing a project and would like to start separating things into smaller parts and also to be able to test those parts, so researching found something about using the *.pri files to be able to make a chain of projects and subprojects, but I was confused how this can be organized and would like some more accessible explanation being that I am still beginner in the area.

Previously the files were all inside: "myapp > core"

I organized the files and folders as follows. NOTE: Just one example, there are many files to organize.

├── core/
│   ├── myMath.h
│   ├── myMath.cpp
│   ├── quadTree.h
│   ├── quadTree.cpp
│   ├── bvh.h
│   ├── bvh.cpp
│   ├── myVec2.h
│   └── myVec2.cpp
├── gui/
│   ├── MainWindow.h
│   ├── MainWindow.cpp
│   ├── Explorer.h
│   ├── Explorer.cpp
│   └── gl/
│               ├── glView.h
│               ├── glView.cpp
│               ├── shaders/
│                          ├── vertex.vert
│                          └── fragment.frag
├── main.cpp
├── myApp.pro
├── Doxyfile
├── README.md
└── resources.qrc

Apparently I need to create a *.pro type file like this in the project root: myapp.pro


TEMPLATE = subdirs

SUBDIRS += core Gui \


Then in each printer I must create a *.pri file that lists the files inside that printer.


HEADERS += myMath. h myVec2.h \

SOURCES += myMath.cpp myVec2.cpp \


But there are some situations that I want/need to get around.

Where should I declare *.pro with myapp configs? That is *.pro which must contain the complete configs. Today my file is more or less like this https://pastebin.com/5msdv8YA

1º: Begin to separate the implementation files from the things of the graphical interface, in the matter of the files, because of the implementation I already do this, I try to leave the GUI the least connected to the code possible.

2º: To be able to test the project in smaller parts. For example: I created a Math class and need to test all functions and returns. For this today I create a separate project and do the tests and when it is apparently all right I throw the files there in the final project.

Three, it’s the same as the second, but it happens with widgets. I created a custom widget and needed to test, so I didn’t want to put it in the final GUI and have to compile the software every single change I made, so I created a simplified separate project where I did the testing, but this I think ends up being bad because the steps of change I end up omitting in the git commit, because it is in another project.

These last two I think could create each part a filter inside the TEST and put a mini design. Example

├── core/
│   ├── myMath.h
│   ├── myMath.cpp
│   ├── myVec2.h
│   └── myVec2.cpp
│              ├── Test/
│                         ├── Math /
│                                   ├── math.pro
│                                   ├── main.cpp
│                         ├── Vec2 /
│                                   ├── vec2.pro
│                                   ├── main.cpp

I accept suggestions!

2 answers

1

The Best answer is unfortunately not to use qmake. Qmake is an old piece of code, barely serviceable, complicated to set up by things out of standard.

Cmake eis best suited for any C++ project right now, and has full integration with Qt. It is used by all operating systems (including windows with visual studio) having become a project management standard.

Cmake allows you to create multiple binary / libraries within a single project (Qmake too, but more complex), so you don’t have to create multiple git repositories with one library just for that, and it also allows partial compilations, changed a file, compiles only this one (and those who depend on it).

Example of Cmakelists for your project:

project(SeuApp)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOUIC ON)

find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets)

# diretorios das bibliotecas que seu codigo vai criar.
add_directory(lib)
add_directory(gui)

#diretorio do executavel, onde ta o main.cpp
add_directory(app)

#diretorio dos testes
enable_testing()
add_directory(tests)

And in each folder you want to have a library, add a Cmakelists.txt file, and use the add_directory in the main cmake for it.

Cmakelists.txt from the app would look something like this:

add_executable(MyExec main.cpp)
target_link_libraries(MyExec Qt5::Gui Qt5::Core Qt5::Widgets lib gui)

0

Do so in your .pro

QT  += core gui

QT  += widgets #caso esteja abrindo um projeto de versao antiga em versao nova

TARGET = my_App
TEMPLATE = app

include (core/core.pri)

include (gui/gui.pri)


SOURCES += main.cpp\

HEADERS += main.h\

RESOURCES += \resourcers.qrc


Na pasta gui:
crie um arquivo chamado core.pri e escreva nele

include (gl/gl.pri)

SOURCES += MainWindow.cpp\

Explorer.cpp\

.
.
.

HEADERS += MainWindow.h\

Explorer.h\

.
.
.

And then it goes on with the other sub-folders...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.