Qt LAN chat


Original Address https://blog.csdn.net/tsvico/article/details/94721560

This design is a simple LAN chat, group chat is divided into functional design and whisper two parts, each part will support basic chat and file transfer capabilities, whisper page compared to the main page to support more features, such as Wink Send window jitter, voice chat and so on. Refer to the "Qt and Qt Quick development of real refined solution" in Chapter 5 Group Chat instance, on the basis of group chat whisper this part of the design and other features. Here are the overall design and implementation.

This document will be written according to the order start

  • The design here is the ip address of the host, you can use multiple hosts running the program for testing to ensure that multiple hosts connected to the same local area network, before commissioning process found may be detected multiple local LAN IP, it needs to start at the beginning of the program manually select the test list an IP.
    Select IP

Transfer files, private chat, voice uses the TCP, UDP, UDP, UDP which is mainly used for storage of different operating status message (new users join, the transmission, the file transfer message, refuse to accept the file, the user leaves, enter the private chat stage), and then sent to the other clients so as to ensure real-time broadcast by each client, each client receives different messages in response to execution state operation. Belonging to a new user joins a program execution stage, then all users are in the same interface, corresponding to the stage group chat, group chat messages can be sent. TCP is used to transfer files, when receiving the transfer file sent by the UPD message, send the file as one end Server, accept the file as one of the Client-side, to realize the transmission between the point.

Users

For new users join we will show the user name of the host, each adding a client, display the user name, host name (the presence of this column but was artificially hidden), IP address with other clients and its own client, and the message xxx record box shows online, then either send messages to receive messages in real time to other clients, to achieve the group chat feature (Figure I). When a client closes or exit the program at this point in time to leave the record box displays a message box, and then when a new user is added time and show xxx online again. (Native LAN IP is 172.16.22.48), another client IP (172.16.22.53)

Figure I
Figure II
The key here is the transmission line in broadcast constructor main interface, transmits a broadcast closed off

Interface Introduction

  • Respectively represent the message font style, font size, bold, italic, underline, color, theme, select the file;
  • Receiving the message box is voice chat, video calls (not implemented), file transfer, remote desktop.
  • IP switching is selected skin left, to the following figure




  • Screenshot interface display
    Here Insert Picture Description

    File transfer

  • Group chat interface:
    • Before file transfer, we first selected to be sent to the IP address, select the host from the display information on the right, if not checked, it will prompt the user does not select and re-select, select the IP after receiving the file (you can select group chat own IP test), click on the file transfer button on the message entry box, then enter the Server interface file to send. Select the file transmission is transmitted, then another selected user pop Client file reception screen, select whether to receive.
  • Whisper
    Whisper click interface files directly, and the same effect as the main interface

Private chat

  • Show host information from the right side of the box, double-click, in order to facilitate testing, where you can chat and themselves. When the user double-click, then pop up private chat interface, and displays a certain chat, obtaining its IP address. The other received the message will appear on the main page "XXX whisper a message is being sent to you."
    Whisper
  • Jitter send window
    windowed jitter flag, after sending a message, the receiver receives the message window vertically and horizontally in different amplitude jitter
QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "pos");
pAnimation->setDuration(500);
pAnimation->setLoopCount(2);
pAnimation->setKeyValueAt(0, QPoint(geometry().x() - 3, geometry().y() - 3));
pAnimation->setKeyValueAt(0.1, QPoint(geometry().x() + 6, geometry().y() + 6));
pAnimation->setKeyValueAt(0.2, QPoint(geometry().x() - 6, geometry().y() + 6));
pAnimation->setKeyValueAt(0.3, QPoint(geometry().x() + 6, geometry().y() - 6));
pAnimation->setKeyValueAt(0.4, QPoint(geometry().x() - 6, geometry().y() - 6));
pAnimation->setKeyValueAt(0.5, QPoint(geometry().x() + 6, geometry().y() + 6));
pAnimation->setKeyValueAt(0.6, QPoint(geometry().x() - 6, geometry().y() + 6));
pAnimation->setKeyValueAt(0.7, QPoint(geometry().x() + 6, geometry().y() - 6));
pAnimation->setKeyValueAt(0.8, QPoint(geometry().x() - 6, geometry().y() - 6));
pAnimation->setKeyValueAt(0.9, QPoint(geometry().x() + 6, geometry().y() + 6));
pAnimation->setKeyValueAt(1, QPoint(geometry().x() - 3, geometry().y() - 3));
pAnimation->start(QAbstractAnimation::DeleteWhenStopped);
  • Voice Send
    create voice flag to send a message in order to send voice can be heard but also to receive voice transmission. To send a voice broadcast closed party canceled voice, while closing the other voice transmission. In order to ensure that the receiver and the sender while closing, the closing event where overwriting
void autrans::closeEvent(QCloseEvent *e){
    emit meclose(); //发送关闭信号
    QWidget::closeEvent(e);
}
  • Wink Send
    create a new tableview in private chat interface will look through the code loaded into the UI interface
void priroom::addEmotionItem(int row,int low,int lo)
{
    QLabel* label1 = new QLabel;
    QString path = ":/emoji/%1.gif";
    QMovie *movie =new QMovie(path.arg(lo+1));
    movie->setScaledSize(QSize(25,25));
    label1->setMovie(movie);
    ui->tableWidget->setCellWidget(row,low,label1);
    movie->start();
}

Click to get the ranks of the position to calculate the path of the picture, will send a wink

  • and many more

Other details

  • Support List renamed

Summary: basically it so much, there is no registration, login function, for the operation of the database, which also intends to add back in, we can see the code interpretation "Qt and Qt Quick development of real refined solution" this book, for private we can talk about this also download the source link below, add a lot of notes, and qDebug debugging.

Video Display (Recording here earlier did not voice chat, if you can not play click here )

Topics section Reference

Application testing link (double-click the .exe file):
https://www.lanzous.com/i4unced

Guess you like

Origin www.cnblogs.com/tsvico/p/12244473.html