資源描述:
《linux下即時(shí)通訊軟件》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、Main#include#include"widget.h"intmain(intargc,char*argv[]){QApplicationa(argc,argv);Widgetw;QTextCodec::setCodecForTr(QTextCodec::codecForLocale());#ifdefined(Q_WS_S60)w.showMaximized();#elsew.show();#endifreturna.exec();}Widget#inc
2、lude"widget.h"#include"ui_widget.h"Widget::Widget(QWidget*parent):QWidget(parent),ui(newUi::Widget){ui->setupUi(this);this->resize(850,550);ui->textEdit->setFocusPolicy(Qt::StrongFocus);ui->textBrowser->setFocusPolicy(Qt::NoFocus);ui->textEdit->setFocu
3、s();ui->textEdit->installEventFilter(this);udpSocket=newQUdpSocket(this);port=45454;udpSocket->bind(port,QUdpSocket::ShareAddress
4、QUdpSocket::ReuseAddressHint);connect(udpSocket,SIGNAL(readyRead()),this,SLOT(processPendingDatagrams()));sendMessage(NewP
5、articipant);server=newTcpServer(this);connect(server,SIGNAL(sendFileName(QString)),this,SLOT(sentFileName(QString)));connect(ui->textEdit,SIGNAL(currentCharFormatChanged(QTextCharFormat)),this,SLOT(currentFormatChanged(constQTextCharFormat)));}voidWidg
6、et::currentFormatChanged(constQTextCharFormat&format){//當(dāng)編輯器的字體格式改變時(shí),我們讓部件狀態(tài)也隨之改變ui->fontComboBox->setCurrentFont(format.font());if(format.fontPointSize()<9)//如果字體大小出錯(cuò),因?yàn)槲覀冏钚〉淖煮w為9ui->fontsizecomboBox->setCurrentIndex(3);//即顯示12elseui->fontsizecomboBox-
7、>setCurrentIndex(ui->fontsizecomboBox->findText(QString::number(format.fontPointSize())));ui->textbold->setChecked(format.font().bold());ui->textitalic->setChecked(format.font().italic());ui->textUnderline->setChecked(format.font().underline());color=f
8、ormat.foreground().color();}voidWidget::processPendingDatagrams()//接收數(shù)據(jù)UDP{while(udpSocket->hasPendingDatagrams()){QByteArraydatagram;datagram.resize(udpSocket->pendingDatagramSize());udpSocket->readDatagram(datagram.data(),datagram.size());QDataStream
9、in(&datagram,QIODevice::ReadOnly);intmessageType;in>>messageType;QStringuserName,localHostName,ipAddress,message;QStringtime=QDateTime::currentDateTime().toString("yyyy-MM-ddhh:mm:ss");switch(messageType){caseMessage:{in>>userName>>loca