[cpp] Add catch and qt examples
This commit is contained in:
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