`
ydbc
  • 浏览: 719789 次
  • 性别: Icon_minigender_1
  • 来自: 大连
文章分类
社区版块
存档分类
最新评论

QT 网络通讯软件群聊源码

 
阅读更多

QT 网络通讯软件群聊源码

xteam.h-------------------------------------------------------------

#include<QtGui>
#include <QtGui/QWidget>
#include <QtNetwork>
#include <QTcpSocket>
#include <QUdpSocket>
#include <QAbstractSocket>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QPushButton>
#include <QString>
#include <QMainWindow>
#include <QPixmap>
#include <QFileInfo>
#include "ui_teamchat.h"
//#include "xselectface1.h"
class Team:public QMainWindow, public Ui::MainWindow
{
Q_OBJECT
public:
Team(int,int,QString,QStringList);
void messagefirmx(int ,QString ,QString );
private:
int id;
int userid;
QString sname;
QStringList nlist;
void list_init();
//selectfacemm *ssselectface;

//QString pic;
quint16 tcpport;
quint16 udpport;
//QTcpServer *server;
QTcpSocket *clientsocket;
QUdpSocket *udpsocket;
QHostAddress address;
QPixmap screenshot;
void writeDate(int flag);

void closeEvent(QCloseEvent *event);


private slots:
void setFontColor();
void setBoldFont(bool flag);
void setFontxx();
void windowshot();
//void sendFileSlot();
//void sendImageSlot();
//void showEmotionSlot();
//void showfaceSlot(QString);
void sendMessageSlot();
//void readMessageSlot();
void requestconnectSlot();
//void messagefirmSlot(int,QString,QString);
//void appendpushbuttonSlot();
//void messangeconfirm();

signals:
void closebutton(int);
//void friendmessage(QString,int);

};

team.cpp-------------------------------------------------------------------------

#include"xteam.h"
Team::Team(int userid,int id,QString sname,QStringList nlist)
{
setupUi(this);
this->userid=userid;
this->id=id;
this->sname=sname;
this->nlist=nlist;
list_init();
label->setNum(id);
textEdit->setReadOnly(true);
//ssselectface = new selectfacemm();

////////////////////////////////////////
//网络设定
tcpport = 60001;
address = "192.168.2.231";
udpport = 45454;
clientsocket = new QTcpSocket(this);
udpsocket = new QUdpSocket(this);
udpsocket->bind(QHostAddress::Any, udpport);
//工具按钮状态
toolButton_Font_3->setCheckable(true);
toolButton_Font_4->setCheckable(true);
toolButton_Font_2->setCheckable(true);
//信号和槽
connect(pushButton_3, SIGNAL(clicked()), this, SLOT(close()));
connect(toolButton_Font_5, SIGNAL(clicked()), this, SLOT(setFontColor()));
connect(toolButton_Font_3, SIGNAL(toggled(bool)), textEdit_2, SLOT(setFontItalic(bool)));
connect(toolButton_Font_4, SIGNAL(toggled(bool)), textEdit_2, SLOT(setFontUnderline(bool)));
connect(toolButton_Font_2, SIGNAL(toggled(bool)), this, SLOT(setBoldFont(bool)));
connect(toolButton_Font, SIGNAL(clicked()), this, SLOT(setFontxx()));
connect(toolButton_Font_7, SIGNAL(clicked()), this, SLOT(windowshot()));
//connect(toolButton_Font_6, SIGNAL(clicked()), this, SLOT(showEmotionSlot()));
//connect(ssselectface, SIGNAL(showiconSignal( QString )), this, SLOT(showfaceSlot(QString)));
connect(pushButton, SIGNAL(clicked()),this, SLOT(requestconnectSlot()));
connect(clientsocket, SIGNAL(connected()), this, SLOT(sendMessageSlot()));

}
void Team::list_init()
{
QTreeWidgetItem *a[50];
int d=0;
treeWidget->clear();
treeWidget->setColumnCount(2);
treeWidget->setColumnHidden (1,true );
QTreeWidgetItem *teamheadItem = new QTreeWidgetItem();
treeWidget->setHeaderItem(teamheadItem);
teamheadItem->setText(0, nlist.at(0));
teamheadItem->setText(1, nlist.at(1));
teamheadItem->setTextColor(0,QColor::QColor(255,255,0));
for(int i=2 ; i<nlist.size();i++)
{
a[d] = new QTreeWidgetItem();
treeWidget->addTopLevelItem(a[d]);
a[d]->setText(0,tr("%1(%2)")
.arg(nlist.at(i))
.arg(nlist.at(i+1)));
a[d]->setText(1,nlist.at(i+1));
i++;
d++;
}
}
//槽函数,设置字体颜色
void Team::setFontColor()
{
QColor col = QColorDialog::getColor(textEdit_2->textColor(), this);
if (!col.isValid())
{
return;
}
textEdit_2->setTextColor(col);

QPixmap pix(16, 16);
pix.fill(col);
toolButton_Font_5->setIcon(pix);
this->setStatusTip(tr("set FontColor"));
}
//槽函数,设置输入字体为粗体
void Team::setBoldFont(bool flag)
{
if(flag == true)
{
textEdit_2->setFontWeight(QFont::Bold);
}
else
textEdit_2->setFontWeight(QFont::Normal);
this->setStatusTip(tr("set BoldFont"));
}
//槽函数,设置字体大小+选择字体
void Team::setFontxx()
{
bool ok;
QFont font = QFontDialog::getFont(&ok, QFont("Times", 12), this);
if (!ok)
{
return;
}
textEdit_2->setFont(font);
this->setStatusTip(tr("set FontSize"));
}
//槽函数,添加表情图片
/*
void Team::showEmotionSlot()
{

ssselectface->show();
this->setStatusTip(tr("add Facepic"));
}*/
//槽函数,快速抓屏
void Team::windowshot()
{
screenshot = QPixmap::grabWindow(QApplication::desktop()->winId(),0,0,QApplication::desktop()->width(),QApplication::desktop()->height());
QString format = "png";
QString picName = QFileDialog::getSaveFileName(this, tr("Save As"),
"temp-image/",
tr("%1 Files (*.%2);;All Files (*)")
.arg(format.toUpper())
.arg(format));


if (!picName.isEmpty())
screenshot.save(picName, format.toAscii());
textEdit_2->append("<img src='temp-image/" + QFileInfo(picName).fileName() + "' />");

this->setStatusTip(tr("windowshot"));

}
//槽函数,把图片放入Textedit内
/*
void Team::showfaceSlot(QString pic )
{
textEdit_2->append("<img src='"+pic+"' />");
}*/
void Team::requestconnectSlot()
{
clientsocket->abort();
clientsocket->connectToHost(address,tcpport);
this->setStatusTip(tr("connect Ready"));
}
void Team::sendMessageSlot()
{
this->setStatusTip(tr(" send a message"));
writeDate(6);
}
void Team::writeDate(int flag)
{
QDataStream out;
out.setVersion(QDataStream::Qt_4_0);
out.setDevice(clientsocket);
int groupid = id;
int useid = userid;
QString kname = sname;
out << flag << useid;
if(flag == 6)
{out << groupid << kname;
out << textEdit_2->toHtml();
}

textEdit_2->clear();
}
void Team::messagefirmx(int xid,QString xmessage,QString sayname)
{
if(id == xid)
{
textEdit->append( "/n[ " + QDateTime::currentDateTime().toString(tr("yyyy-MM-dd hh:mm:ss"))
+ " ] " + sayname + tr(" say:/n/t") );
textEdit->append(xmessage);
}
}
void Team::closeEvent(QCloseEvent *event)
{
emit closebutton(id);
event->accept();
}

《转 为亲身验证 分析代码没有问题》
分享到:
评论

相关推荐

    基于Qt开发的翻译软件源码.zip

    基于Qt开发的翻译软件源码.zip基于Qt开发的翻译软件源码.zip基于Qt开发的翻译软件源码.zip基于Qt开发的翻译软件源码.zip基于Qt开发的翻译软件源码.zip基于Qt开发的翻译软件源码.zip基于Qt开发的翻译软件源码.zip基于...

    QGis+qt实现缩略图工程源码,没有运行环境,需自己配置运行环境

    QGis+qt实现缩略图工程源码QGis+qt实现缩略图工程源码QGis+qt实现缩略图工程源码QGis+qt实现缩略图工程源码QGis+qt实现缩略图工程源码QGis+qt实现缩略图工程源码QGis+qt实现缩略图工程源码QGis+qt实现缩略图工程源码...

    基于Qt设计的网络聊天软件(界面仿QQ,支持群聊、私聊).zip

    这是基于Qt设计的网络聊天软件,资料包里包含了Qt的源码、也带了一份可执行文件,设计文档说明,涉及的知识点文档。 源码分为两份,一份服务器代码,一份客户端代码。 运行时,需要先运行服务器,再启动客户端即可...

    期末大作业C++课程设计基于Qt实现图书管理系统源码.zip

    期末大作业C++课程设计基于Qt实现图书管理系统源码,VS开发。期末大作业C++课程设计基于Qt实现图书管理系统源码,VS开发。期末大作业C++课程设计基于Qt实现图书管理系统源码,VS开发。期末大作业C++课程设计基于Qt...

    Qt摄像头视频监测软件源码

    Qt摄像头视频监测软件源码

    qt源码 最好用的源码

    qt源码 最好用的源码 qt源码 最好用的源码 qt源码 最好用的源码

    QT停车场管理系统源码.rar

    QT停车场管理系统源码QT停车场管理系统源码QT停车场管理系统源码QT停车场管理系统源码QT停车场管理系统源码QT停车场管理系统源码QT停车场管理系统源码QT停车场管理系统源码QT停车场管理系统源码QT停车场管理系统源码...

    Qt5编程入门+源码.7z.003

    Qt5编程入门+源码.7z.003 Qt5编程入门+源码.7z.003 Qt5编程入门+源码.7z.003

    Qt上位机软件串口通讯,视频源码,免费下载

    Qt上位机软件串口通讯,视频源码,免费下载,视频上我的b站主页找https://space.bilibili.com/401094174

    《Qt5编程入门》源码

    《Qt5编程入门》源码,包括所有章节所涉及的源码程序,下载解压后可以直接运行看效果 《Qt5编程入门》源码,包括所有章节所涉及的源码程序,下载解压后可以直接运行看效果

    C++基于Arm和Qt的智能车载系统源码(也可C++本科毕业设计).zip

    C++基于Arm和Qt的智能车载系统源码。实现了天气预报、音乐播放器、视频播放器、倒车雷达、行车记录仪、多语言切换等功能。,利用Qt C++完成主要部分功能模块C++基于Arm和Qt的智能车载系统源码。实现了天气预报、音乐...

    QT聊天系统实现群聊私聊等功能

    QT实现群聊和私聊等功能,类是QQ,基于tcpip协议的

    Qt基于数据库的学生管理系统源码.zip

    Qt基于数据库的学生管理系统源码 Qt基于数据库的学生管理系统源码 Qt基于数据库的学生管理系统源码 Qt基于数据库的学生管理系统源码 Qt基于数据库的学生管理系统源码 Qt基于数据库的学生管理系统源码...

    基于Qt的Android实时投屏软件源码.zip

    基于Qt的Android实时投屏软件源码.zip基于Qt的Android实时投屏软件源码.zip 基于Qt的Android实时投屏软件源码.zip基于Qt的Android实时投屏软件源码.zip 基于Qt的Android实时投屏软件源码.zip基于Qt的Android实时投屏...

    qt的开源项目源码

    qt的开源项目源码qt的开源项目源码qt的开源项目源码qt的开源项目源码

    Qt环境截图软件源码

    Qt环境截图软件源码,可使用(Ctrl+X)快捷键触发截图事件和(Ctrl+S)快捷键触发保存事件

    基于QT的医院管理系统源码.zip

    基于QT的医院管理系统源码.zip基于QT的医院管理系统源码.zip基于QT的医院管理系统源码.zip基于QT的医院管理系统源码.zip基于QT的医院管理系统源码.zip基于QT的医院管理系统源码.zip基于QT的医院管理系统源码.zip基于...

    基于qt的校园导航系统源码+项目说明.zip

    基于qt的校园导航系统源码+项目说明.zip基于qt的校园导航系统源码+项目说明.zip基于qt的校园导航系统源码+项目说明.zip基于qt的校园导航系统源码+项目说明.zip基于qt的校园导航系统源码+项目说明.zip基于qt的校园...

    QT+c++编写的IEC104通讯源码

    QT+c++编写的IEC104通讯源码,模拟IEC04通讯流程,对于初学者还是很有帮助的!

Global site tag (gtag.js) - Google Analytics