看起来像函数定义,但没有参数列表;跳过明显的函数体?
//tcpserver.h
#ifndef TCPSERVER_H
#define TCPSERVER_H
#include "tcpthread.h"
#include <QTcpServer>
class tcpserver : public QTcpServer
{
Q_OBJECT
public:
explicit tcpserver(QObject *parent = 0);
//QList<int> clientDescriptorList;
signals:
void newRow(int);
void displayInfo(int,QString, int);
void updateBar(int, qint64);
void signal_send_command(int,int);
public slots:
void incomingConnection(int socketDescriptor);
void slot_send_command(int,int);
};
#endif
//tcpserver.cpp
#include "tcpserver.h"
//构造函数
tcpserver::tcpserver(QObject *parent):
QTcpServer(parent)
{
}
//重新定义了incomingConnection这个虚函数,
//开辟一个新的tcpsocket线程,从TcpServer获得socketDescriptor,
//并完成相应的信号连接
void tcpserver::incomingConnection(int socketDescriptor)
{
qDebug() <<socketDescriptor;
//clientDescriptorList.append(socketDescriptor);
emit newRow(socketDescriptor); //display new client
connect(this,SIGNAL(signal_send_command(int ,int)),this,SLOT(slot_send_command(int ,int)));
}
void tcpserver::slot_send_command(int sockDescriptor, int cmd)
{
TcpThread *thread = new TcpThread(sockDescriptor,cmd, this);
thread->start();
connect(thread,SIGNAL(finished()),this,SLOT(deleteLater()));
connect(thread,SIGNAL(displayInfo(int,QString,int)),this,SIGNAL(displayInfo(int,QString,int)));
connect(thread,SIGNAL(updateBar(int,qint64)),this,SIGNAL(updateBar(int,qint64)));
}