From deb5b8eae04dbcffd23ceea86772901b7a20e0b1 Mon Sep 17 00:00:00 2001 From: Andrey Astafyev Date: Thu, 20 Oct 2022 13:17:24 +0300 Subject: [PATCH] 0.4.0 --- CMakeLists.txt | 6 +- include/myx-example-features/processor.hpp | 27 +++++ src/myx-example-features/main.cpp | 121 +++++++++++++++++++++ src/myx-example-features/processor.hpp | 26 +++++ 4 files changed, 177 insertions(+), 3 deletions(-) create mode 100644 include/myx-example-features/processor.hpp create mode 100644 src/myx-example-features/main.cpp create mode 100644 src/myx-example-features/processor.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 27cd103..3bb4324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,18 +5,18 @@ cmake_minimum_required(VERSION 3.6 FATAL_ERROR) cmake_policy(VERSION 3.6..3.7) # Название и версия проекта и используемые языки программирования -project(myx-example-features VERSION 0.3.0 LANGUAGES CXX) +project(myx-example-features VERSION 0.4.0 LANGUAGES CXX) # Рекомендуемый способ подключения MyxCMake include(cmake/myx_setup.cmake) # Поиск пакетов -myx_find_packages( +myx_find_required_packages( Qt5 Core Qt5Private Core) # Цель для создания исполняемого файла -add_executable(${PROJECT_NAME}) +myx_add_executable(${PROJECT_NAME}) # Настройка свойств цели myx_target_setup(${PROJECT_NAME} diff --git a/include/myx-example-features/processor.hpp b/include/myx-example-features/processor.hpp new file mode 100644 index 0000000..bf7e3a5 --- /dev/null +++ b/include/myx-example-features/processor.hpp @@ -0,0 +1,27 @@ +/** + * \file Класс Processor + */ + +#ifndef PROCESSOR_HPP_ +#define PROCESSOR_HPP_ + +#pragma once + +#include +#include + +/** + * \brief Класс Processor + */ +class Processor : public QObject +{ + Q_OBJECT +public: + /** + * \brief Слот, печатающий сообщение + */ + Q_SLOT void process() { qCritical() << "about to close"; } +}; + +#endif // ifndef PROCESSOR_HPP_ +// EOF processor.hpp diff --git a/src/myx-example-features/main.cpp b/src/myx-example-features/main.cpp new file mode 100644 index 0000000..4bfd508 --- /dev/null +++ b/src/myx-example-features/main.cpp @@ -0,0 +1,121 @@ +/** + * \file Основной файл проекта + */ + +#include + +#include +#include +#include +#include +#include + +/** + * @brief Перевод строки в целое число + * @param Строка + * @return Целое число + */ +int qStringToInt( const QString& s ) +{ + return( s.toInt() ); +} + + +/** + * \brief Неиспользуемая функция для тестирования анализа покрытия кода + */ +int unused( int a ) +{ + return( a ); +} + + +/** + * \brief Медленная функция + */ +int slowFunction() +{ + constexpr int size = 16 * 1024; + double a[size]; + + for ( int i = 0; i < size; i++ ) + { + a[i] = QRandomGenerator::global()->bounded( 4 ); + for ( int j = 0; j < i; j++ ) a[i] += sin( a[j] ); + a[0] += a[i]; + } + return( qRound( a[0] ) ); +} // slowFunction + + +/** + * \brief Быстрая функция + */ +int fastFunction() +{ + constexpr int size = 8 * 1024; + double a[size]; + + for ( int i = 0; i < size; i++ ) + { + a[i] = QRandomGenerator::global()->bounded( 4 ); + for ( int j = 0; j < i; j++ ) a[i] += sin( a[j] ); + a[0] += a[i]; + } + return( qRound( a[0] ) ); +} + + +/** + * \brief Основная функция + * \param argc Количество параметров командной строки + * \param argv Массив параметров + * \return Результат выполнения QApplication::exec() + */ +int main( int argc, char** argv ) +{ + QCoreApplication app( argc, argv ); + + // qt-keywords + QList< int > il; + + il << 111 << 222; + Q_FOREACH ( int i, il ) + { + qDebug() << i; + } + + QStringList sl; + + sl << QStringLiteral( "111" ) << QStringLiteral( "222" ); + for ( const auto& s: qAsConst( sl ) ) + { + qDebug() << s; + } + + for ( auto s: qAsConst( sl ) ) + { + s.append( "0" ); + } + + QString s { QStringLiteral( "100" ) }; + auto ir = qStringToInt( s ); + + QFile* f = new QFile(); + Processor p; + + QObject::connect( &app, &QCoreApplication::aboutToQuit, &p, &Processor::process ); + QTimer::singleShot( 100, &app, SLOT(quit())); + + #ifdef PROFILE + qCritical() << "Slow: " << slowFunction(); + qCritical() << "Fast: " << fastFunction(); + #endif + + int arr[3]; + qCritical() << arr[2]; + return( QCoreApplication::exec() ); +}// main + + +// EOF main.cpp diff --git a/src/myx-example-features/processor.hpp b/src/myx-example-features/processor.hpp new file mode 100644 index 0000000..4c60659 --- /dev/null +++ b/src/myx-example-features/processor.hpp @@ -0,0 +1,26 @@ +/** + * \file Класс Processor + */ + +#ifndef PROCESSOR_HPP_ +#define PROCESSOR_HPP_ + +#pragma once + +#include +#include + +/** + * \brief Класс Processor + */ +class Processor : public QObject +{ + Q_OBJECT +public: + /** + * \brief Слот, печатающий сообщение + */ + Q_SLOT void process() { qCritical() << "about to close"; } +}; + +#endif // ifndef PROCESSOR_HPP_