summaryrefslogtreecommitdiffstats
path: root/tests/manual/corelib/tools/customtypesending
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/corelib/tools/customtypesending')
-rw-r--r--tests/manual/corelib/tools/customtypesending/CMakeLists.txt16
-rw-r--r--tests/manual/corelib/tools/customtypesending/customtypesending.pro9
-rw-r--r--tests/manual/corelib/tools/customtypesending/main.cpp31
-rw-r--r--tests/manual/corelib/tools/customtypesending/message.cpp19
-rw-r--r--tests/manual/corelib/tools/customtypesending/message.h34
-rw-r--r--tests/manual/corelib/tools/customtypesending/window.cpp43
-rw-r--r--tests/manual/corelib/tools/customtypesending/window.h35
7 files changed, 187 insertions, 0 deletions
diff --git a/tests/manual/corelib/tools/customtypesending/CMakeLists.txt b/tests/manual/corelib/tools/customtypesending/CMakeLists.txt
new file mode 100644
index 0000000000..c22d5e23c1
--- /dev/null
+++ b/tests/manual/corelib/tools/customtypesending/CMakeLists.txt
@@ -0,0 +1,16 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
+cmake_minimum_required(VERSION 3.16)
+
+qt_internal_add_manual_test(customtypesending
+ GUI
+ SOURCES
+ main.cpp
+ message.cpp message.h
+ window.cpp window.h
+ LIBRARIES
+ Qt6::Core
+ Qt6::Gui
+ Qt6::Widgets
+)
diff --git a/tests/manual/corelib/tools/customtypesending/customtypesending.pro b/tests/manual/corelib/tools/customtypesending/customtypesending.pro
new file mode 100644
index 0000000000..d316787f76
--- /dev/null
+++ b/tests/manual/corelib/tools/customtypesending/customtypesending.pro
@@ -0,0 +1,9 @@
+HEADERS = message.h \
+ window.h
+SOURCES = main.cpp \
+ message.cpp \
+ window.cpp
+QT += widgets
+INCLUDEPATH += .
+TARGET = customtypesending
+
diff --git a/tests/manual/corelib/tools/customtypesending/main.cpp b/tests/manual/corelib/tools/customtypesending/main.cpp
new file mode 100644
index 0000000000..a8f95ffe8e
--- /dev/null
+++ b/tests/manual/corelib/tools/customtypesending/main.cpp
@@ -0,0 +1,31 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QApplication>
+#include "message.h"
+#include "window.h"
+
+//! [main function]
+int main(int argc, char *argv[])
+{
+ QApplication app(argc, argv);
+
+ QStringList headers;
+ headers << "Subject: Hello World"
+ << "From: address@example.com";
+ QString body = "This is a test.\r\n";
+ Message message(body, headers);
+
+ Window window1;
+ window1.setMessage(message);
+
+ Window window2;
+ QObject::connect(&window1, &Window::messageSent,
+ &window2, &Window::setMessage);
+ QObject::connect(&window2, &Window::messageSent,
+ &window1, &Window::setMessage);
+ window1.show();
+ window2.show();
+ return app.exec();
+}
+//! [main function]
diff --git a/tests/manual/corelib/tools/customtypesending/message.cpp b/tests/manual/corelib/tools/customtypesending/message.cpp
new file mode 100644
index 0000000000..a7a8722673
--- /dev/null
+++ b/tests/manual/corelib/tools/customtypesending/message.cpp
@@ -0,0 +1,19 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "message.h"
+
+Message::Message(const QString &body, const QStringList &headers)
+ : m_body(body), m_headers(headers)
+{
+}
+
+QString Message::body() const
+{
+ return m_body;
+}
+
+QStringList Message::headers() const
+{
+ return m_headers;
+}
diff --git a/tests/manual/corelib/tools/customtypesending/message.h b/tests/manual/corelib/tools/customtypesending/message.h
new file mode 100644
index 0000000000..b16c92f177
--- /dev/null
+++ b/tests/manual/corelib/tools/customtypesending/message.h
@@ -0,0 +1,34 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef MESSAGE_H
+#define MESSAGE_H
+
+#include <QMetaType>
+#include <QStringList>
+
+//! [custom type definition]
+class Message
+{
+public:
+ Message() = default;
+ ~Message() = default;
+ Message(const Message &) = default;
+ Message &operator=(const Message &) = default;
+
+ Message(const QString &body, const QStringList &headers);
+
+ QString body() const;
+ QStringList headers() const;
+
+private:
+ QString m_body;
+ QStringList m_headers;
+};
+//! [custom type definition]
+
+//! [custom type meta-type declaration]
+Q_DECLARE_METATYPE(Message);
+//! [custom type meta-type declaration]
+
+#endif
diff --git a/tests/manual/corelib/tools/customtypesending/window.cpp b/tests/manual/corelib/tools/customtypesending/window.cpp
new file mode 100644
index 0000000000..fc158f10e6
--- /dev/null
+++ b/tests/manual/corelib/tools/customtypesending/window.cpp
@@ -0,0 +1,43 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QtWidgets>
+#include "window.h"
+
+//! [Window constructor]
+Window::Window(QWidget *parent)
+ : QWidget(parent), editor(new QTextEdit(this))
+{
+ QPushButton *sendButton = new QPushButton(tr("&Send message"));
+
+ connect(sendButton, &QPushButton::clicked,
+ this, &Window::sendMessage);
+
+ QHBoxLayout *buttonLayout = new QHBoxLayout;
+ buttonLayout->addStretch();
+ buttonLayout->addWidget(sendButton);
+ buttonLayout->addStretch();
+
+ QVBoxLayout *layout = new QVBoxLayout(this);
+ layout->addWidget(editor);
+ layout->addLayout(buttonLayout);
+
+ setWindowTitle(tr("Custom Type Sending"));
+}
+//! [Window constructor]
+
+//! [sending a message]
+void Window::sendMessage()
+{
+ thisMessage = Message(editor->toPlainText(), thisMessage.headers());
+ emit messageSent(thisMessage);
+}
+//! [sending a message]
+
+//! [receiving a message]
+void Window::setMessage(const Message &message)
+{
+ thisMessage = message;
+ editor->setPlainText(thisMessage.body());
+}
+//! [receiving a message]
diff --git a/tests/manual/corelib/tools/customtypesending/window.h b/tests/manual/corelib/tools/customtypesending/window.h
new file mode 100644
index 0000000000..974e7a7629
--- /dev/null
+++ b/tests/manual/corelib/tools/customtypesending/window.h
@@ -0,0 +1,35 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#ifndef WINDOW_H
+#define WINDOW_H
+
+#include <QWidget>
+#include "message.h"
+
+QT_FORWARD_DECLARE_CLASS(QTextEdit)
+
+//! [Window class definition]
+class Window : public QWidget
+{
+ Q_OBJECT
+
+public:
+ Window(QWidget *parent = nullptr);
+
+signals:
+ void messageSent(const Message &message);
+
+public slots:
+ void setMessage(const Message &message);
+
+private slots:
+ void sendMessage();
+
+private:
+ Message thisMessage;
+ QTextEdit *editor;
+};
+//! [Window class definition]
+
+#endif