From fa1078a31358afb56e6db40614810b6d07528799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kjist=C3=B3f?= Date: Sun, 4 Dec 2016 20:30:27 +0100 Subject: [PATCH] added a hander for returnPressed() in QLineEdit of GUI --- chat_window.hpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/chat_window.hpp b/chat_window.hpp index fd92cbf..0dce1ac 100644 --- a/chat_window.hpp +++ b/chat_window.hpp @@ -10,17 +10,24 @@ class chat_window : public QWidget { Q_OBJECT -public: - explicit chat_window(QWidget* parent = 0) - :QWidget(parent) - { setupUi(); } - -private: QGridLayout* _layout; QListWidget* _chat; QListWidget* _people; QLineEdit* _msg; +public: + explicit chat_window(QWidget* parent = 0) + :QWidget(parent) + { setupUi(); } + +public slots: + void return_handler() + { + _chat->addItem(_msg->text()); + _msg->clear(); + }; + +private: void setupUi() { this->setWindowTitle("C++11Chat"); @@ -31,6 +38,7 @@ private: _people = new QListWidget(); _msg = new QLineEdit(); + connect(_msg, &QLineEdit::returnPressed, this, &chat_window::return_handler); _layout->addWidget(_chat, 0, 0, 1, 1); _layout->addWidget(_people, 0, 1, 1, 2);