qq_35383915 2016-08-27 09:43 采纳率: 0%
浏览 1346
已结题

信号函数需要定义么?

头函数
#ifndef SERVER_H
#define SERVER_H

#include
#include
#include "tcpclientsocket.h"
class Server:public QTcpServer
{
public:
Server(QObject parent=0,int port =0);
QList<TcpClientSocket
> tcpClientSocketList;
public slots:
void updateClients(QString,int);
void slotDisconnected(int);
protected:
void incomingConnection(int socketDescriptor);
signals:
void updateServer(QString,int);
};

#endif SERVER_H
函数
#include "server.h"

Server::Server(QObject *parent,int port):QTcpServer(parent)
{
listen(QHostAddress::Any,port);
}
void Server::incomingConnection(int socketDescriptor)
{
TcpClientSocket *tcpClientSocket = new TcpClientSocket(this);
connect(tcpClientSocket,SIGNAL(updateClients(QString,int)),this,SLOT(updateClients(QString,int)));
connect(tcpClientSocket,SIGNAL(disconnected(int)),this,SLOT(slotDisconnected(int)));
tcpClientSocket->setSocketDescriptor(socketDescriptor);
tcpClientSocketList.append(tcpClientSocket);
}
void Server::updateClients(QString msg, int length)
{
emit updateServer(msg,length);
for(int i=0;i {
QTcpSocket *item = tcpClientSocketList.at(i);
if(item->write(msg.toLatin1(),length)!=length)
{
continue;
}
}
}
void Server::slotDisconnected(int descriptor)
{
for(int i=0;i {
QTcpSocket *item=tcpClientSocketList.at(i);
if(item->socketDescriptor()==descriptor)
{
tcpClientSocketList.removeAt(i);
return;
}
}
return;
}
其中出了个问题error: LNK2019: 无法解析的外部符号 "public: void __cdecl Server::updateServer(class QString,int)" (?updateServer@Server@@QEAAXVQString@@H@Z),该符号在函数 "public: void __cdecl Server::updateClients(class QString,int)" (?updateClients@Server@@QEAAXVQString@@H@Z) 中被引用

造着书模仿的,不知道为什么错

  • 写回答

4条回答 默认 最新

  • yunyunxiongsd 2016-08-27 10:10
    关注

    signals:
    void updateServer(QString,int); //现在信号函数变成你自己声明的了 不是系统的 需要定义

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大