Qt CLI 01

A project will be created using cmake. You can see the most relevant captures:

CMakeLists.txt

# indicates that the cmake version must be >= 3.16

cmake_minimum_required(VERSION 3.16)

# indicates the name of the project and that it will be used c++

project(aprendiendoCLists01 LANGUAGES CXX)

# Enables automatic file processing ui files

set(CMAKE_AUTOUIC ON)

#Enables automatic file processing moc files (MetaObjectCompiler)

set(CMAKE_AUTOMOC ON)

# Enables automatic file processing resources files .qrc

set(CMAKE_AUTORCC ON)

# c++ version 17

set(CMAKE_CXX_STANDARD 17)

# mandatory use of C++17

set(CMAKE_CXX_STANDARD_REQUIRED ON)

#it is required (REQUIRED) and requires the Core module

#find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Core)

find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Core)

# indicates sources and executables

add_executable(aprendiendoCLists01

  main.cpp

)

# links the executable to the Core library

target_link_libraries(aprendiendoCLists01 Qt${QT_VERSION_MAJOR}::Core)

# includes the specified module that defines a set of variables,

# among them ${CMAKE_INSTALL_BINDIR}: Directory of binaries and

# ${CMAKE_INSTALL_LIBDIR}: Library directory.

include(GNUInstallDirs)

# TARGETS: directory install the generated executable.

# LIBRARY: For shared libraries

# RUNTIME: directory where the executable will be installed

install(TARGETS aprendiendoCLists01

    LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}

    RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}

)

main.cpp

#include <QCoreApplication>

#include <QDebug>

int main(int argc, char *argv[])

{

    /*

    Manages the event loop for CLI applications

    It is the core of any Qt application which does not require

    graphic interface (instead of QApplication,

    used for graphic applications

    */

    QCoreApplication a(argc, argv);

    qDebug() << «Hello world»;

    // starts the event loop and returns the result value

    return a.exec();

}

grafeno30

Computer science teacher, former analyst/programmer for the Andalusian Regional Government. He holds a degree in computer engineering from the Higher Technical School of Seville.

Ver todas las entradas