newConnection()
クラスのシグナルを介してクラスのスロットを呼び出そうとしますQTcpServer
。connect()
関数は を返しますtrue
が、スロットは実行されませんでした。
これが私が作ったものです:
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();
}
うまくいかないのはなぜですか?