Organization of projects with qMake

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 by researching I found something about using * .pri files to be able to make a chain of projects and subprojects, but I was confused how can this be organized and would like some more accessible explanation being that I'm still a beginner in the field.

Previously the files were all within:  "myApp & core"

I organized the files and folders as follows. OBS: 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 file like this in the project root: myApp.pro

TEMPLATE = subdirs

SUBDIRS + = \             core             gui \

Then in each folder I should create a * .pri file that lists the files within that folder.

HEADERS + = \             myMath.h \             myVec2.h \

SOURCES + = \             myMath.cpp \             myVec2.cpp \

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

Where should I declare * .pro with myApp configs? In other words, * .pro which must contain the complete configs. Today my file looks like this link

asked by anonymous 09.08.2017 / 18:21

2 answers

1

The best answer is unfortunately not to use qmake. QMake is an old piece of code that barely gets maintenance, complicated to set up for non-standard things.

CMake is currently the most suitable for any C ++ project, and has full Qt integration. It is used by all operating systems (including windows with visual studio) and has become a project management standard.

CMake allows you to create multiple binaries / libraries within a single project (QMake too, but in a more complex way), so you do not need to create multiple git repositories with a library just for this, and it too allows partial compilations, changed a file, compiles only that (and those that 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.

The CMakeLists.txt app would look something like this:

add_executable(MyExec main.cpp)
target_link_libraries(MyExec Qt5::Gui Qt5::Core Qt5::Widgets lib gui)
    
09.08.2017 / 18:37
0

Do so on 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 there you go with the other sub-folders ...

    
09.08.2017 / 19:37