{
Q_OBJECT
public:
cServer(int port, int max_num){ max_cnt_num = max_num; this->init_tcpserver(port); }
cServer(int port){ max_cnt_num = MAX_CNT_NUM; this->init_tcpserver(port); }
~cServer();
int cnt_num;
private:
int max_cnt_num;
QTcpServer tcpServer;
bool init_tcpserver(int port)
{
if(!(this->tcpServer.listen(QHostAddress::Any, port)))
std::cout << "端口:"<< port << "开始监听失败" << std::endl;
QObject::connect( &(this->tcpServer),
SIGNAL(newConnection()),
this,
SLOT(acpt_connection()));
};
public slots:
void acpt_connection()
{
this->cnt_num++;
if (this->cnt_num > this->max_cnt_num)
{
std::cout << "连接达到极限" << std::endl;
return ;
}
std::cout << "正在和第" << this->cnt_num << "个请求建立连接" << std::endl;
//new cThreadPoll(&(this->tcpServer.nextPendingConnection()));
}
};
no matching function for call to 'QObject::connect( ...)'
包含了 QObject 头文件了 怎么还是找不到这个函数呢?
2 个解决方案
#1
class cServer
{
Q_OBJECT
......
}
cServer必须继承QObject,也就是:
class cServer:public QObject
{
Q_OBJECT
......
}
{
Q_OBJECT
......
}
cServer必须继承QObject,也就是:
class cServer:public QObject
{
Q_OBJECT
......
}
#2
谢谢.这个问题看了好久了.
呵呵 纯新 自学c++的
呵呵 纯新 自学c++的
#1
class cServer
{
Q_OBJECT
......
}
cServer必须继承QObject,也就是:
class cServer:public QObject
{
Q_OBJECT
......
}
{
Q_OBJECT
......
}
cServer必须继承QObject,也就是:
class cServer:public QObject
{
Q_OBJECT
......
}
#2
谢谢.这个问题看了好久了.
呵呵 纯新 自学c++的
呵呵 纯新 自学c++的