文档详情

linux下即时通讯软件.doc

发布:2017-06-18约2.13万字共20页下载文档
文本预览下载声明
Main #include QtGui/QApplication #include widget.h int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); #if defined(Q_WS_S60) w.showMaximized(); #else w.show(); #endif return a.exec(); } Widget #include widget.h #include ui_widget.h Widget::Widget(QWidget *parent) : QWidget(parent), ui(new Ui::Widget) { ui-setupUi(this); this-resize(850,550); ui-textEdit-setFocusPolicy(Qt::StrongFocus); ui-textBrowser-setFocusPolicy(Qt::NoFocus); ui-textEdit-setFocus(); ui-textEdit-installEventFilter(this); udpSocket = new QUdpSocket(this); port = 45454; udpSocket-bind(port,QUdpSocket::ShareAddress | QUdpSocket::ReuseAddressHint); connect(udpSocket,SIGNAL(readyRead()),this,SLOT(processPendingDatagrams())); sendMessage(NewParticipant); server = new TcpServer(this); connect(server,SIGNAL(sendFileName(QString)),this,SLOT(sentFileName(QString))); connect(ui-textEdit,SIGNAL(currentCharFormatChanged(QTextCharFormat)),this,SLOT(currentFormatChanged(const QTextCharFormat))); } void Widget::currentFormatChanged(const QTextCharFormat format) {//当编辑器的字体格式改变时,我们让部件状态也随之改变 ui-fontComboBox-setCurrentFont(format.font()); if(format.fontPointSize()9) //如果字体大小出错,因为我们最小的字体为9 ui-fontsizecomboBox-setCurrentIndex(3); //即显示12 else ui-fontsizecomboBox-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 = format.foreground().color(); } void Widget::processPendingDatagrams() //接收数据UDP { while(udpSocket-hasPendingDatagrams()) { QByteArray datagram; datagram.resize(udpSocket-pendingDatagramSize()); udpSocket-readDatagram(datagram.data(),dat
显示全部
相似文档