52 lines
1.6 KiB
C++
52 lines
1.6 KiB
C++
#include "server.h"
|
|
#include "Widget.h"
|
|
|
|
#if _MSC_VER >= 1600
|
|
#pragma execution_character_set("utf-8")
|
|
#endif
|
|
|
|
|
|
Server::Server(QObject *parent) :
|
|
QTcpServer(parent)
|
|
{
|
|
qRegisterMetaType<qintptr>("qintptr");
|
|
/*不一定行 需查阅
|
|
* QThread是否允许近对象异步线程友元?*/
|
|
m_widget = dynamic_cast<Widget *>(parent);
|
|
}
|
|
|
|
|
|
Server::~Server()
|
|
{
|
|
|
|
}
|
|
|
|
void Server::incomingConnection(qintptr sockDesc)//当有一个新的连接到来 Server处理
|
|
{
|
|
serverThread *thread = new serverThread(sockDesc);
|
|
|
|
connect(thread, SIGNAL(ShowIP(QString)), this, SLOT(clientConnected(QString)));//某套接字断开连接 列表里删去
|
|
connect(thread, SIGNAL(disconnectTCP(QString)), this, SLOT(clientDisconnected(QString)));//某套接字断开连接 列表里删去
|
|
connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));//某个套接字结束生命周期
|
|
connect(thread, SIGNAL(IMGdataReady(const QString&, const QByteArray&, QString )), //save 要保存的照片来了
|
|
m_widget, SLOT(IMGrecvDataSlot(const QString&, const QByteArray&, QString)));
|
|
connect(thread, SIGNAL(LiveViewIMG(qintptr, QImage)), //Live View 要预览的照片好了
|
|
m_widget, SLOT(ShowLiveView(qintptr, QImage)));
|
|
connect(m_widget, SIGNAL(sendData(QString, const QByteArray&)), //主线程要求套接字发送
|
|
thread, SLOT(sendDataSlot(QString, const QByteArray&)));
|
|
|
|
thread->start();
|
|
|
|
}
|
|
|
|
void Server::clientConnected(QString IP)
|
|
{
|
|
m_widget->showConnection(IP);
|
|
}
|
|
|
|
|
|
void Server::clientDisconnected(QString IP)
|
|
{
|
|
m_widget->showDisconnection(IP);
|
|
}
|