0

newConnection()クラスのシグナルを介してクラスのスロットを呼び出そうとしますQTcpServerconnect()関数は を返します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();
}

うまくいかないのはなぜですか?

4

1 に答える 1