资源简介
Qt项目实例,大量实战项目,供你参考,不要错过。
代码片段和文件信息
/*
* ChessServer.cpp
*
* Created on: 2010-4-19
* Author: Administrator
*/
#include “ChessServer.h“
#include “chess_zn.h“
#include
#include
Chess_ZN * chess;
ChessServer::ChessServer(QWidget *parent): QDialog(parent)
{
pendCount = iCount= 0;
id = 1;
timer = new QTimer;
peer = new PeerManager(1);
peer->setServerPort(10000); ////监听已开启等待客户端试探性连接
socudp = peer->returnUdp();
chess = qobject_cast(parent);
vblay = new QVBoxLayout;
for (int i = 0; i < 3; i++) {
formlay[i] = new QFormLayout;
}
line[0] = new QLineEdit(“9999“);
line[1] = new QLineEdit(“32“);
label[0]= new QLabel(Chess_ZN::utf(“游戏端口“));
label[1]= new QLabel(Chess_ZN::utf(“连接上限“));
button[0]=new QPushButton(Chess_ZN::utf(“开启“));
button[1]=new QPushButton(Chess_ZN::utf(“取消“));
for(int i = 0; i < 2; ++i) {
formlay[i]->addRow(label[i]line[i]);
}
formlay[2]->addRow(button[0]button[1]);
for(int i = 0; i < 3; ++i) {
vblay->addLayout(formlay[i]);
}
connect(button[0]SIGNAL(clicked())thisSLOT(createServer()));
connect(button[1]SIGNAL(clicked())thisSLOT(close()));
connect(socudp SIGNAL(readyRead()) this SLOT(readUdpData()));
connect(timer SIGNAL(timeout()) this SLOT(flushINFO()));
timer->start(2000);
this->setFixedSize(200140);
this->setLayout(vblay);
isDatabase = true;
connection=new Connection;
if(!connection->createConnection()){
//exit(1);
isDatabase = false;
}
if(isDatabase){
connection->setQsqlquery();//创表
}
}
void ChessServer::createServer(){
bool okisok;
line[0]->setValidator(new QIntValidator(065535this));
int port = line[0]->text().toInt(&ok 10);
int max = line[1]->text().toInt(&isok 10);
if(ok==true && isok==true && max >1){
pendCount = max;
tcpServer = new QTcpServer(this);
tcpServer->setMaxPendingConnections(max);
if (!tcpServer->listen(QHostAddress::Anyport)) {
QMessageBox::critical(this Chess_ZN::utf(“服务器信息“)Chess_ZN::utf(tr(“不能开启服务器: %1.“).arg(tcpServer->errorString())));
close();
return;
}
connect(tcpServerSIGNAL(newConnection())thisSLOT(newConnection()));
this->setVisible(false);
chess->action2[0]->setText(Chess_ZN::utf(“取消服务器“));
}else{
line[0]->setText(“9999“);
line[1]->setText(“32“);
QMessageBox::warning(thisChess_ZN::utf(“对不起“)Chess_ZN::utf(“请您正常填写“)QMessageBox::Ok);
return;
}
}
void ChessServer::newConnection(){
if(iCount < pendCount){
tcpclient = tcpServer->nextPendingConnection();
map.insert(tcpclient->peerAddress().toString()tcpclient);
connect(tcpclientSIGNAL(readyRead())thisSLOT(readData()));
connect(tcpclientSIGNAL(error(QAbstractSocket::SocketError))thisSLOT(error(QAbstractSocket::SocketError)));
}
}
void ChessServer::readData(){
QTcpSocket * client=qobject_cast
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 4165 2010-05-12 18:07 应用项目\Chess\.cproject
....... 2899 2010-05-12 18:07 应用项目\Chess\.project
....... 972 2010-05-12 18:07 应用项目\Chess\Chess.pro
....... 688 2010-05-12 18:07 应用项目\Chess\chess.qrc
....... 30051 2010-05-12 18:07 应用项目\Chess\chess_zn.cpp
....... 2242 2010-05-12 18:07 应用项目\Chess\chess_zn.h
....... 437 2010-05-12 18:07 应用项目\Chess\chess_zn.ui
....... 8331 2010-05-12 18:07 应用项目\Chess\ChessServer.cpp
....... 1491 2010-05-12 18:07 应用项目\Chess\ChessServer.h
....... 8554 2010-05-12 18:07 应用项目\Chess\ChessThread.cpp
....... 740 2010-05-12 18:07 应用项目\Chess\ChessThread.h
....... 4448 2010-05-12 18:07 应用项目\Chess\commands.cpp
....... 1474 2010-05-12 18:07 应用项目\Chess\commands.h
....... 922 2010-05-12 18:07 应用项目\Chess\databa
....... 302 2010-05-12 18:07 应用项目\Chess\databa
....... 425 2010-05-12 18:07 应用项目\Chess\databa
....... 513 2010-05-12 18:07 应用项目\Chess\databa
....... 790 2010-05-12 18:07 应用项目\Chess\databa
....... 296 2010-05-12 18:07 应用项目\Chess\databa
....... 1636636 2010-05-12 18:07 应用项目\Chess\debug\chess_zn.o
....... 1556757 2010-05-12 18:07 应用项目\Chess\debug\ChessServer.o
....... 1480975 2010-05-12 18:07 应用项目\Chess\debug\ChessThread.o
....... 1346039 2010-05-12 18:07 应用项目\Chess\debug\commands.o
....... 934029 2010-05-12 18:07 应用项目\Chess\debug\connection.o
....... 538262 2010-05-12 18:07 应用项目\Chess\debug\diagramitem.o
....... 1477559 2010-05-12 18:07 应用项目\Chess\debug\diagramscene.o
....... 1435027 2010-05-12 18:07 应用项目\Chess\debug\main.o
....... 15964 2010-05-12 18:07 应用项目\Chess\debug\mingwm10.dll
....... 3723 2010-05-12 18:07 应用项目\Chess\debug\moc_chess_zn.cpp
....... 1448772 2010-05-12 18:07 应用项目\Chess\debug\moc_chess_zn.o
............此处省略487个文件信息
评论
共有 条评论