My dedicated QQ functions (II)

Source: Internet
Author: User

 

Next

 

 

 

? Friend list

 

 

 

 

 

 

Related initialization, UDP

 

Void panel: init ()

{

UdpSocket = new QUdpSocket (this );

UdpSocket-> bind (6666 );

QString msgType = "MSG_CLIENT_NEW_CONN ";

QByteArray block;

QDataStream out (& block, QIODevice: WriteOnly );

Out. setVersion (QDataStream: Qt_4_6 );

Out <(quint16) 0 <msgType <usrname;

Out. device ()-> seek (0 );

UdpSocket-> writeDatagram (block. data (), block. size (), QHostAddress (ip), (quint16) port. toUInt () + 1 );

Connect (this-> udpSocket, SIGNAL (readyRead (), this, SLOT (recvMsg ()));

}

 

 

 

List display

 

Void panel: on_itemDoubleClicked (QListWidgetItem * item)

{

QString nameStr = ui-> usrlistWidget-> currentItem ()-> text ();

 

NameStr. replace ("\ n ","");

Chatform * c = chatformHash. value (nameStr );

If (c = 0)

{

C = new chatform (this-> usrname, this-> ip, this-> port, udpSocket );

C-> setWindowTitle ("chatting with" + nameStr + ".");

ChatformHash. insert (nameStr, c );//??

 

}

C-> setWindowFlags (Qt: FramelessWindowHint );

C-> setAttribute (Qt: WA_TranslucentBackground );

 

C-> show ();

}

 

 

 

? Chat Window

 

 

 

 

Display and processing of chat Information

 

Void chatform: displayText (QString nickname, QString usrname, QString text)

{

QListWidgetItem * displayItem = new QListWidgetItem (nickname + "(" + usrname + "): \ n" + text + "\ n ");

Ui-> listWidget-> addItem (displayItem );

}

 

Sending Processing

 

Void chatform: on_sendButton ()

{

QString sendText = ui-> textEdit-> toPlainText ();

If (! SendText. isEmpty ())

{

QString windowTitle = this-> windowTitle (). replace ("].", "");

QString toId = QString (windowTitle. split ("["). at (1 ));

QString msgType = "MSG_CLIENT_CHAT ";

QByteArray block;

QDataStream out (& block, QIODevice: WriteOnly );

Out. setVersion (QDataStream: Qt_4_6 );

Out <(quint16) 0 <msgType <usrname <toId <sendText;

Out. device ()-> seek (0 );

 

Out <(quint16) (block. size ()-sizeof (quint16 ));

 

UdpSocket-> writeDatagram (block. data (), block. size (), QHostAddress (serverIp), (quint16) serverPort. toUInt () + 1 );

Ui-> listWidget-> addItem ("I say: \ n" + sendText + "\ n ");

}

Ui-> textEdit-> clear ();

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.