[cpp] Add catch and qt examples
This commit is contained in:
22
cpp/qt/CMakeLists.txt
Normal file
22
cpp/qt/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
################################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: A root project for practicing Qt 6 projects in C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(
|
||||
#[[NAME]] Klips
|
||||
VERSION 1.0
|
||||
DESCRIPTION "A root project for several small cpp practice projects"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||
add_compile_options("-Wall")
|
||||
|
||||
add_subdirectory(designer)
|
||||
add_subdirectory(slots)
|
||||
52
cpp/qt/designer/CMakeLists.txt
Normal file
52
cpp/qt/designer/CMakeLists.txt
Normal file
@@ -0,0 +1,52 @@
|
||||
################################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Practice project for using Qt Designer with custom C++ widgets ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(
|
||||
#[[NAME]] Designer
|
||||
VERSION 0.1
|
||||
DESCRIPTION "Practice using Qt designer for desktop applications"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_compile_options(-Wall)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/" CACHE PATH "Path to Qt6")
|
||||
|
||||
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_add_executable(designer
|
||||
designer.cpp designer.h designer.ui
|
||||
debugconsole.h debugconsole.cpp debugconsole.ui
|
||||
texteditor.h texteditor.cpp texteditor.ui
|
||||
treeview.h treeview.cpp treeview.ui
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(designer PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(designer PUBLIC Qt::Core Qt::Gui Qt::Widgets)
|
||||
|
||||
install(TARGETS designer
|
||||
RUNTIME DESTINATION "install/designer"
|
||||
BUNDLE DESTINATION "install/designer"
|
||||
LIBRARY DESTINATION "install/designer"
|
||||
)
|
||||
186
cpp/qt/designer/CMakeLists.txt.user
Normal file
186
cpp/qt/designer/CMakeLists.txt.user
Normal file
@@ -0,0 +1,186 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE QtCreatorProject>
|
||||
<!-- Written by QtCreator 8.0.1, 2022-12-17T17:29:08. -->
|
||||
<qtcreator>
|
||||
<data>
|
||||
<variable>EnvironmentId</variable>
|
||||
<value type="QByteArray">{ce8a8d3d-318d-4c62-a573-71d1755252ce}</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.ActiveTarget</variable>
|
||||
<value type="qlonglong">0</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.EditorSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="bool" key="EditorConfiguration.AutoIndent">true</value>
|
||||
<value type="bool" key="EditorConfiguration.AutoSpacesForTabs">false</value>
|
||||
<value type="bool" key="EditorConfiguration.CamelCaseNavigation">true</value>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.0">
|
||||
<value type="QString" key="language">Cpp</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">CppGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="EditorConfiguration.CodeStyle.1">
|
||||
<value type="QString" key="language">QmlJS</value>
|
||||
<valuemap type="QVariantMap" key="value">
|
||||
<value type="QByteArray" key="CurrentPreferences">QmlJSGlobal</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="EditorConfiguration.CodeStyle.Count">2</value>
|
||||
<value type="QByteArray" key="EditorConfiguration.Codec">UTF-8</value>
|
||||
<value type="bool" key="EditorConfiguration.ConstrainTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.IndentSize">4</value>
|
||||
<value type="bool" key="EditorConfiguration.KeyboardTooltips">false</value>
|
||||
<value type="int" key="EditorConfiguration.MarginColumn">80</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseHiding">true</value>
|
||||
<value type="bool" key="EditorConfiguration.MouseNavigation">true</value>
|
||||
<value type="int" key="EditorConfiguration.PaddingMode">1</value>
|
||||
<value type="bool" key="EditorConfiguration.PreferSingleLineComments">false</value>
|
||||
<value type="bool" key="EditorConfiguration.ScrollWheelZooming">true</value>
|
||||
<value type="bool" key="EditorConfiguration.ShowMargin">false</value>
|
||||
<value type="int" key="EditorConfiguration.SmartBackspaceBehavior">0</value>
|
||||
<value type="bool" key="EditorConfiguration.SmartSelectionChanging">true</value>
|
||||
<value type="bool" key="EditorConfiguration.SpacesForTabs">true</value>
|
||||
<value type="int" key="EditorConfiguration.TabKeyBehavior">0</value>
|
||||
<value type="int" key="EditorConfiguration.TabSize">8</value>
|
||||
<value type="bool" key="EditorConfiguration.UseGlobal">true</value>
|
||||
<value type="bool" key="EditorConfiguration.UseIndenter">false</value>
|
||||
<value type="int" key="EditorConfiguration.Utf8BomBehavior">1</value>
|
||||
<value type="bool" key="EditorConfiguration.addFinalNewLine">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanIndentation">true</value>
|
||||
<value type="bool" key="EditorConfiguration.cleanWhitespace">true</value>
|
||||
<value type="QString" key="EditorConfiguration.ignoreFileTypes">*.md, *.MD, Makefile</value>
|
||||
<value type="bool" key="EditorConfiguration.inEntireDocument">false</value>
|
||||
<value type="bool" key="EditorConfiguration.skipTrailingWhitespace">true</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.PluginSettings</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<valuemap type="QVariantMap" key="AutoTest.ActiveFrameworks">
|
||||
<value type="bool" key="AutoTest.Framework.Boost">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.CTest">false</value>
|
||||
<value type="bool" key="AutoTest.Framework.Catch">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.GTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtQuickTest">true</value>
|
||||
<value type="bool" key="AutoTest.Framework.QtTest">true</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="AutoTest.CheckStates"/>
|
||||
<value type="int" key="AutoTest.RunAfterBuild">0</value>
|
||||
<value type="bool" key="AutoTest.UseGlobal">true</value>
|
||||
<valuemap type="QVariantMap" key="ClangTools">
|
||||
<value type="bool" key="ClangTools.AnalyzeOpenFiles">true</value>
|
||||
<value type="bool" key="ClangTools.BuildBeforeAnalysis">true</value>
|
||||
<value type="QString" key="ClangTools.DiagnosticConfig">Builtin.DefaultTidyAndClazy</value>
|
||||
<value type="int" key="ClangTools.ParallelJobs">4</value>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedDirs"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SelectedFiles"/>
|
||||
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
|
||||
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
|
||||
</valuemap>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Target.0</variable>
|
||||
<valuemap type="QVariantMap">
|
||||
<value type="QString" key="DeviceType">Desktop</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Qt 6.3.1 GCC 64bit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Qt 6.3.1 GCC 64bit</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">{6ade7dd7-47b1-42f6-b09c-570bb7fbeb1c}</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveBuildConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveDeployConfiguration">0</value>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.ActiveRunConfiguration">0</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.BuildConfiguration.0">
|
||||
<value type="QString" key="CMake.Build.Type">Debug</value>
|
||||
<value type="QString" key="CMake.Initial.Parameters">-DCMAKE_GENERATOR:STRING=Ninja
|
||||
-DCMAKE_BUILD_TYPE:STRING=Debug
|
||||
-DCMAKE_PROJECT_INCLUDE_BEFORE:FILEPATH=%{IDE:ResourcePath}/package-manager/auto-setup.cmake
|
||||
-DQT_QMAKE_EXECUTABLE:FILEPATH=%{Qt:qmakeExecutable}
|
||||
-DCMAKE_PREFIX_PATH:PATH=%{Qt:QT_INSTALL_PREFIX}
|
||||
-DCMAKE_C_COMPILER:FILEPATH=%{Compiler:Executable:C}
|
||||
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
|
||||
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}</value>
|
||||
<value type="QString" key="CMake.Source.Directory">/home/kapper/Code/klips/cpp/qt/designer</value>
|
||||
<value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/home/kapper/Code/klips/cpp/qt/designer/cmake-build-debug</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
|
||||
<value type="QString">all</value>
|
||||
</valuelist>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Build</value>
|
||||
</valuemap>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.1">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
|
||||
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
|
||||
<value type="QString">clean</value>
|
||||
</valuelist>
|
||||
<value type="bool" key="ProjectExplorer.BuildStep.Enabled">true</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Build</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.MakeStep</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">1</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Clean</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Clean</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">2</value>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ClearSystemEnvironment">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.CustomParsers"/>
|
||||
<value type="bool" key="ProjectExplorer.BuildConfiguration.ParseStandardOutput">false</value>
|
||||
<valuelist type="QVariantList" key="ProjectExplorer.BuildConfiguration.UserEnvironmentChanges"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Debug</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">CMakeProjectManager.CMakeBuildConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.BuildConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.DeployConfiguration.0">
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
|
||||
<value type="qlonglong" key="ProjectExplorer.BuildStepList.StepsCount">0</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DefaultDisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.DisplayName">Deploy</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.BuildSteps.Deploy</value>
|
||||
</valuemap>
|
||||
<value type="int" key="ProjectExplorer.BuildConfiguration.BuildStepListCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.DeployConfiguration.CustomData"/>
|
||||
<value type="bool" key="ProjectExplorer.DeployConfiguration.CustomDataEnabled">false</value>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.DefaultDeployConfiguration</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.DeployConfigurationCount">1</value>
|
||||
<valuemap type="QVariantMap" key="ProjectExplorer.Target.RunConfiguration.0">
|
||||
<value type="bool" key="Analyzer.Perf.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.QmlProfiler.Settings.UseGlobalSettings">true</value>
|
||||
<value type="bool" key="Analyzer.Valgrind.Settings.UseGlobalSettings">true</value>
|
||||
<valuelist type="QVariantList" key="CustomOutputParsers"/>
|
||||
<value type="int" key="PE.EnvironmentAspect.Base">2</value>
|
||||
<valuelist type="QVariantList" key="PE.EnvironmentAspect.Changes"/>
|
||||
<value type="QString" key="ProjectExplorer.ProjectConfiguration.Id">ProjectExplorer.CustomExecutableRunConfiguration</value>
|
||||
<value type="QString" key="ProjectExplorer.RunConfiguration.BuildKey"></value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseCppDebuggerAuto">true</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
|
||||
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
|
||||
</valuemap>
|
||||
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
|
||||
</valuemap>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.TargetCount</variable>
|
||||
<value type="qlonglong">1</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>ProjectExplorer.Project.Updater.FileVersion</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
<data>
|
||||
<variable>Version</variable>
|
||||
<value type="int">22</value>
|
||||
</data>
|
||||
</qtcreator>
|
||||
18
cpp/qt/designer/debugconsole.cpp
Normal file
18
cpp/qt/designer/debugconsole.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Debug console widget made in Qt Designer with C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include "debugconsole.h"
|
||||
#include "ui_debugconsole.h"
|
||||
|
||||
DebugConsole::DebugConsole(QWidget *parent)
|
||||
: QDockWidget(parent), ui(new Ui::DebugConsole) {
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
DebugConsole::~DebugConsole() { delete ui; }
|
||||
29
cpp/qt/designer/debugconsole.h
Normal file
29
cpp/qt/designer/debugconsole.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Debug console widget made in Qt Designer with C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#ifndef DEBUGCONSOLE_H
|
||||
#define DEBUGCONSOLE_H
|
||||
|
||||
#include "ui_debugconsole.h"
|
||||
#include <QDockWidget>
|
||||
|
||||
class DebugConsole : public QDockWidget {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DebugConsole(QWidget *parent = nullptr);
|
||||
~DebugConsole();
|
||||
|
||||
inline QPlainTextEdit *getConsole() { return ui->plainTextEdit; }
|
||||
|
||||
private:
|
||||
Ui::DebugConsole *ui;
|
||||
};
|
||||
|
||||
#endif // DEBUGCONSOLE_H
|
||||
26
cpp/qt/designer/debugconsole.ui
Normal file
26
cpp/qt/designer/debugconsole.ui
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>DebugConsole</class>
|
||||
<widget class="QDockWidget" name="DebugConsole">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>DockWidget</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="plainTextEdit"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
30
cpp/qt/designer/designer.cpp
Normal file
30
cpp/qt/designer/designer.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: MainWindow for Qt Designer desktop application ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include <QtWidgets>
|
||||
|
||||
#include "debugconsole.h"
|
||||
#include "designer.h"
|
||||
#include "texteditor.h"
|
||||
#include "treeview.h"
|
||||
|
||||
Designer::Designer(QWidget *parent)
|
||||
: QMainWindow(parent), designer_(new Ui::Designer) {
|
||||
designer_->setupUi(this);
|
||||
setCentralWidget(new TextEditor);
|
||||
auto debugConsole = new DebugConsole;
|
||||
debugConsole->getConsole()->appendPlainText("Test 1");
|
||||
debugConsole->getConsole()->appendPlainText("Test 2");
|
||||
|
||||
auto treeView = new TreeView;
|
||||
|
||||
addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, debugConsole);
|
||||
addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, treeView);
|
||||
sendTest();
|
||||
}
|
||||
39
cpp/qt/designer/designer.h
Normal file
39
cpp/qt/designer/designer.h
Normal file
@@ -0,0 +1,39 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: MainWindow for Qt Designer desktop application ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#ifndef KLIPS_SLOTSAPP_H
|
||||
#define KLIPS_SLOTSAPP_H
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QMainWindow>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
#include "ui_designer.h"
|
||||
|
||||
class Designer : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
Designer(QWidget *parent = nullptr);
|
||||
~Designer() = default;
|
||||
|
||||
public:
|
||||
signals:
|
||||
void sendTest();
|
||||
|
||||
public slots:
|
||||
void test(){};
|
||||
|
||||
private:
|
||||
Ui::Designer *designer_;
|
||||
};
|
||||
|
||||
#endif // KLIPS_SLOTSAPP_H
|
||||
37
cpp/qt/designer/designer.ui
Normal file
37
cpp/qt/designer/designer.ui
Normal file
@@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Designer</class>
|
||||
<widget class="QMainWindow" name="Designer">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>600</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>MainWindow</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="centralwidget"/>
|
||||
<widget class="QMenuBar" name="menubar">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>22</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
<property name="title">
|
||||
<string>File</string>
|
||||
</property>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
</widget>
|
||||
<widget class="QStatusBar" name="statusbar"/>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
19
cpp/qt/designer/main.cpp
Normal file
19
cpp/qt/designer/main.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Main driver program for Qt Designer desktop application.. ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include "designer.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char * argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
Designer qtk;
|
||||
qtk.show();
|
||||
// Show widget.
|
||||
return app.exec();
|
||||
}
|
||||
23
cpp/qt/designer/texteditor.cpp
Normal file
23
cpp/qt/designer/texteditor.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Dockable text editor widget made in Qt Designer with C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include "texteditor.h"
|
||||
#include "ui_texteditor.h"
|
||||
|
||||
TextEditor::TextEditor(QWidget *parent) :
|
||||
QDockWidget(parent),
|
||||
ui(new Ui::TextEditor)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
TextEditor::~TextEditor()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
31
cpp/qt/designer/texteditor.h
Normal file
31
cpp/qt/designer/texteditor.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Dockable text editor widget made in Qt Designer with C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#ifndef TEXTEDITOR_H
|
||||
#define TEXTEDITOR_H
|
||||
|
||||
#include <QDockWidget>
|
||||
|
||||
namespace Ui {
|
||||
class TextEditor;
|
||||
}
|
||||
|
||||
class TextEditor : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TextEditor(QWidget *parent = nullptr);
|
||||
~TextEditor();
|
||||
|
||||
private:
|
||||
Ui::TextEditor *ui;
|
||||
};
|
||||
|
||||
#endif // TEXTEDITOR_H
|
||||
17
cpp/qt/designer/texteditor.ui
Normal file
17
cpp/qt/designer/texteditor.ui
Normal file
@@ -0,0 +1,17 @@
|
||||
<ui version="4.0">
|
||||
<class>TextEditor</class>
|
||||
<widget class="QDockWidget" name="TextEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>DockWidget</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents"/>
|
||||
</widget>
|
||||
</ui>
|
||||
23
cpp/qt/designer/treeview.cpp
Normal file
23
cpp/qt/designer/treeview.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Dockable tree view widget made in Qt Designer with C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include "treeview.h"
|
||||
#include "ui_treeview.h"
|
||||
|
||||
TreeView::TreeView(QWidget *parent) :
|
||||
QDockWidget(parent),
|
||||
ui(new Ui::TreeView)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
}
|
||||
|
||||
TreeView::~TreeView()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
31
cpp/qt/designer/treeview.h
Normal file
31
cpp/qt/designer/treeview.h
Normal file
@@ -0,0 +1,31 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Dockable tree view widget made in Qt Designer with C++ ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#ifndef TREEVIEW_H
|
||||
#define TREEVIEW_H
|
||||
|
||||
#include <QDockWidget>
|
||||
|
||||
namespace Ui {
|
||||
class TreeView;
|
||||
}
|
||||
|
||||
class TreeView : public QDockWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit TreeView(QWidget *parent = nullptr);
|
||||
~TreeView();
|
||||
|
||||
private:
|
||||
Ui::TreeView *ui;
|
||||
};
|
||||
|
||||
#endif // TREEVIEW_H
|
||||
26
cpp/qt/designer/treeview.ui
Normal file
26
cpp/qt/designer/treeview.ui
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>TreeView</class>
|
||||
<widget class="QDockWidget" name="TreeView">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>400</width>
|
||||
<height>300</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>DockWidget</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="dockWidgetContents">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QTreeView" name="treeView"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
50
cpp/qt/slots/CMakeLists.txt
Normal file
50
cpp/qt/slots/CMakeLists.txt
Normal file
@@ -0,0 +1,50 @@
|
||||
################################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Practice project for using signals and slots in Qt ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
|
||||
cmake_minimum_required(VERSION 3.15)
|
||||
|
||||
project(
|
||||
#[[NAME]] Slots
|
||||
VERSION 1.0
|
||||
DESCRIPTION "Practice using signals and slots in Qt 6"
|
||||
LANGUAGES CXX
|
||||
)
|
||||
|
||||
add_compile_options(-Wall)
|
||||
set(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
set(CMAKE_AUTOUIC ON)
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
set(CMAKE_AUTORCC ON)
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
|
||||
set(QT_DIR "$ENV{HOME}/Code/Clones/Qt/6.3.1/gcc_64/" CACHE PATH "Path to Qt6")
|
||||
|
||||
list(APPEND CMAKE_PREFIX_PATH "${QT_DIR}")
|
||||
|
||||
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
|
||||
|
||||
qt_add_executable(slots
|
||||
text-view.cpp text-view.h
|
||||
slots-app.cpp slots-app.h
|
||||
main.cpp
|
||||
)
|
||||
|
||||
set_target_properties(slots PROPERTIES
|
||||
WIN32_EXECUTABLE TRUE
|
||||
MACOSX_BUNDLE TRUE
|
||||
)
|
||||
|
||||
target_link_libraries(slots PUBLIC Qt::Core Qt::Gui Qt::Widgets)
|
||||
|
||||
install(TARGETS slots
|
||||
RUNTIME DESTINATION "install/slots"
|
||||
BUNDLE DESTINATION "install/slots"
|
||||
LIBRARY DESTINATION "install/slots"
|
||||
)
|
||||
18
cpp/qt/slots/main.cpp
Normal file
18
cpp/qt/slots/main.cpp
Normal file
@@ -0,0 +1,18 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Main driver fprogram for practice using signals and slots in Qt ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include "slots-app.h"
|
||||
#include <QApplication>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
QApplication app(argc, argv);
|
||||
SlotsApp slotsApp;
|
||||
slotsApp.show();
|
||||
return app.exec();
|
||||
}
|
||||
42
cpp/qt/slots/slots-app.cpp
Normal file
42
cpp/qt/slots/slots-app.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: MainWindow application for practice using signals and slots in Qt ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include "slots-app.h"
|
||||
#include "text-view.h"
|
||||
|
||||
SlotsApp::SlotsApp(QWidget *parent) : QMainWindow(parent) {
|
||||
|
||||
auto textBox = new QPlainTextEdit;
|
||||
auto textView = new TextView;
|
||||
auto frame = new QFrame;
|
||||
|
||||
auto dock = new QDockWidget(this);
|
||||
auto dockWidget = new QWidget;
|
||||
auto dockWidgetLayout = new QVBoxLayout;
|
||||
dockWidgetLayout->addWidget(frame);
|
||||
dockWidgetLayout->addWidget(textBox);
|
||||
dockWidget->setLayout(dockWidgetLayout);
|
||||
dock->setWidget(dockWidget);
|
||||
|
||||
auto dock2 = new QDockWidget(this);
|
||||
auto dockWidget2 = new QWidget;
|
||||
auto dockWidgetLayout2 = new QVBoxLayout;
|
||||
dockWidgetLayout2->addWidget(textView);
|
||||
dockWidget2->setLayout(dockWidgetLayout2);
|
||||
dock2->setWidget(dockWidget2);
|
||||
|
||||
textBox->setReadOnly(true);
|
||||
textBox->appendPlainText("Test 1");
|
||||
textBox->appendPlainText("Test 2");
|
||||
|
||||
addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, dock);
|
||||
addDockWidget(Qt::DockWidgetArea::BottomDockWidgetArea, dock2);
|
||||
connect(this, &SlotsApp::sendTest, textView, &TextView::test);
|
||||
sendTest();
|
||||
}
|
||||
34
cpp/qt/slots/slots-app.h
Normal file
34
cpp/qt/slots/slots-app.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: MainWindow application for practice using signals and slots in Qt ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#ifndef KLIPS_SLOTSAPP_H
|
||||
#define KLIPS_SLOTSAPP_H
|
||||
|
||||
#include <QDockWidget>
|
||||
#include <QMainWindow>
|
||||
#include <QPlainTextEdit>
|
||||
#include <QVBoxLayout>
|
||||
#include <QWidget>
|
||||
|
||||
class SlotsApp : public QMainWindow {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SlotsApp(QWidget *parent = nullptr);
|
||||
~SlotsApp() = default;
|
||||
|
||||
public:
|
||||
signals:
|
||||
void sendTest();
|
||||
|
||||
public slots:
|
||||
void test(){};
|
||||
};
|
||||
|
||||
#endif // KLIPS_SLOTSAPP_H
|
||||
10
cpp/qt/slots/text-view.cpp
Normal file
10
cpp/qt/slots/text-view.cpp
Normal file
@@ -0,0 +1,10 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Text viewer for signals and slots examples ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#include "text-view.h"
|
||||
40
cpp/qt/slots/text-view.h
Normal file
40
cpp/qt/slots/text-view.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/*##############################################################################
|
||||
## Author: Shaun Reed ##
|
||||
## Legal: All Content (c) 2022 Shaun Reed, all rights reserved ##
|
||||
## About: Text viewer for signals and slots examples ##
|
||||
## ##
|
||||
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com | GitHub: shaunrd0 ##
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
#ifndef KLIPS_TEXTVIEW_H
|
||||
#define KLIPS_TEXTVIEW_H
|
||||
|
||||
#include <QPlainTextEdit>
|
||||
|
||||
class TextView : public QPlainTextEdit {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
TextView(QWidget *parent = nullptr) {}
|
||||
|
||||
~TextView() = default;
|
||||
|
||||
public:
|
||||
signals:
|
||||
void sendTest();
|
||||
|
||||
private:
|
||||
signals:
|
||||
void sentTestPrivate();
|
||||
|
||||
public slots:
|
||||
void test() { appendPlainText("Test signal received by TextView."); }
|
||||
|
||||
void testArgs(const QString &message) { appendPlainText(message); }
|
||||
|
||||
private slots:
|
||||
void testPrivate() {}
|
||||
};
|
||||
|
||||
#endif // KLIPS_TEXTVIEW_H
|
||||
Reference in New Issue
Block a user