设为首页 加入收藏

TOP

我的专属QQ功能篇 (一) (一)
2014-11-23 22:30:39 来源: 作者: 【 】 浏览:1
Tags:专属 功能

写在开头

之前只总结了透明、无边框、可移动窗口的UI处理,为了给某位同学提供些学习资料,我再总结些功能要点。

原则:少说废话,多上代码。

登录窗口

登录操作TcpSocket,如果你非要问我为什么不是UDP Socket ,我只能说因为tcp可靠。

\

登录

在确保设置IP端口后,通过QDataStream 写QIODevice

void login::on_loginButton()

{

usrname = ui->usrnamelineEdit->text().trimmed();

password = ui->passwordlineEdit->text().trimmed();

QRegExp rx("^[1-9]{1,2}[0-9]{4,7}{1}quot;);

rx.setPatternSyntax(QRegExp::RegExp);

if (!rx.exactMatch(usrname))

{

QMessageBox::warning(NULL, tr("提示"), tr("请输入QQ号."));

}

else

{

tcpSocket->abort();

tcpSocket->connectToHost(QHostAddress(ip), (quint16)port.toUInt());

QString msgType = "MSG_USER_LOGIN";

QByteArray block;

QDataStream out(&block, QIODevice::WriteOnly);

out.setVersion(QDataStream::Qt_4_6);

out << (quint16)0 << msgType << usrname << password;

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

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

tcpSocket->write(block);

}

}

登录反馈

void login::on_Read()

{

QByteArray block = tcpSocket->readAll();

QDataStream in(&block, QIODevice::ReadOnly); //QDataStream in(tcpSocket);

quint16 dataGramSize;

QString msgType;

in >> dataGramSize >> msgType;

if ( "MSG_ID_NOTEXIST" == msgType )

{

QMessageBox::warning(NULL, tr("提示"), tr("该号码不存在,请先注册."));

ui->usrnamelineEdit->clear();

ui->passwordlineEdit->clear();

}

else if ( "MSG_PWD_ERROR" == msgType )

{

QMessageBox::information(NULL, tr("提示"), tr("密码错误."));

ui->usrnamelineEdit->clear();

}

else if ( "MSG_LOGIN_ALREADY" == msgType )

{

QMessageBox::information(NULL, tr("提示"), tr("请不要重复登录."));

ui->usrnamelineEdit->clear();

ui->passwordlineEdit->clear();

}

else if ( "MSG_LOGIN_SUCCESS" == msgType)

{

qqpanel = new panel(usrname, ip, port);

qqpanel->setWindowTitle(tr("QQcopy"));

qqpanel->setWindowFlags(Qt::FramelessWindowHint);

qqpanel->setAttribute(Qt::WA_TranslucentBackground);

qqpanel->show();

this->close();

}

服务器端的监听

\

首先Tcp server

void TcpSockServer::incomingConnection(int socketDescriptor)

{

TcpConThread *thread = new TcpConThread(socketDescriptor, this);

connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));

thread->start();

}

窗口构造

Daemon::Daemon(QWidget *parent) :

QMainWindow(parent),

ui(new Ui::Daemon)

{

ui->setupUi(this);

this->setWindowTitle("QQ");

ui->startListenButton->setText("开始监听");

ui->ipLineEdit->setEnabled(true);

ui->portLineEdit->setEnabled(true);

ip.clear();

port.clear();

db = new SqliteDB;

tableViewRefresh();

}

数据信息的refresh

void Daemon::tableViewRefresh()

{

db->connectDB();

this->myModel = new MySqlQueryModel;

this->myModel->setQuery(QObject::tr("select id, name, logstat from user order by logstat desc"));

myModel->setHeaderData(0, Qt::Horizontal, tr("QQ号"));

myModel->setHeaderData(1, Qt::Horizontal, tr("昵称"));

myModel->setH

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇让你不再害怕指针0--复杂类型说明 下一篇 我的专属QQ功能篇(二)

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: