-
Notifications
You must be signed in to change notification settings - Fork 0
/
ChattingClient.cpp
53 lines (37 loc) · 1.13 KB
/
ChattingClient.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "ChattingClient.h"
#include "ClientThread.h"
#include <QTcpSocket>
#include <QDateTime>
#include <QString>
#include <QQmlListProperty>
// Widgets
#include <QInputDialog>
#include <QLineEdit>
ChattingClient::ChattingClient(QWidget *parent)
{
}
void ChattingClient::connectToServer(const QString &name, const QString& ip) {
ClientThread* thread = new ClientThread(name, ip, this);
this->thread = thread;
thread->start();
}
QQmlListProperty<Message> ChattingClient::messages() {
//return QQmlListProperty<Message>(this, 0, &ChattingClient::append_message);
return QQmlListProperty<Message>(this, m_messages);
}
void ChattingClient::append_message(QQmlListProperty<Message>* list, Message* msg) {
ChattingClient* client = qobject_cast<ChattingClient*>(list->object);
if (msg) {
client->m_messages.prepend(msg);
}
}
void ChattingClient::addMessage(Message* msg) {
this->m_messages.prepend(msg);
emit messagesChanged();
}
void ChattingClient::sendMessage(const QString &message) {
QByteArray arr = message.toUtf8();
Message* myMessage = new Message(arr, "Me");
this->thread->sendMessage(arr);
emit messagesChanged();
}