newConnection()
신호를 통해 클래스의 슬롯을 QTcpServer
클래스로 호출하려고합니다. connect()
함수는 true
을 반환하지만 슬롯은 실행되지 않았습니다.Qt 슬롯이 성공적으로 연결되었지만 해고되지 않았습니다.
여기에 내가 만든 작업은 다음과 같습니다
class server : QObject
{
Q_OBJECT
public:
server();
QTcpServer *srv;
void run();
public slots:
void handleClient();
}
바인드 슬롯 :
void server::run()
{
srv = new QTcpServer();
bool status = connect(srv, SIGNAL(newConnection()), this, SLOT(handleClient()));
// status contains true now
srv->listen(QHostAddress::Any, port);
}
슬롯의 몸 :
void server::handleClient()
{
/* This code is not being executed */
qDebug() << "zxc";
QMessageBox msg;
msg.setText("zxc");
msg.exec();
}
가 왜 작동하지 않는 이유는 무엇입니까?
좋아요. Q_OBJECT 매크로를 클래스에 추가 한 후 qmake를 호출 했습니까? –
'listen'의 반환 값을 확인하고,'false'를 반환하면'errorString()'에 문자열을 추가하십시오. –
@ValentinHeinitz, 네, 제가 이걸 만들었어요. – WildDev