0

dialog.h のコンパイルで問題が発生しました。コンパイラは、QHostAddress::Any が型ではなく、数値定数の前に識別子が必要であると不平を言います。(両方とも、dialog.h の 2 番目から最後の行にあります)。

なぜこれがコンパイルされないのか誰か教えてもらえますか? 私はサーバーオブジェクトをインスタンス化し、サーバーコンストラクターが期待するパラメーターを渡しています...私は思った...

dialog.h

#include <QWidget>
#include <QHostAddress>
#include "server.h"

class QLabel;
class QPushButton;

class Dialog : public QWidget
{
    Q_OBJECT

public:
    Dialog(QWidget *parent = 0);

private:
    QLabel *statusLabel;
    QPushButton *quitButton;
    Server server;
};

サーバー.h:

class Server : public QTcpServer
{
    Q_OBJECT

public:
    Server(QHostAddress listenAddress, quint16 listenPort, QObject *parent = 0);
    QHostAddress hostAddress;
    quint16 hostPort;

protected:
    void incomingConnection(qintptr socketDescriptor);

private:

};

dialog.cpp (部分)

Dialog::Dialog(QWidget *parent)
    : QWidget(parent), server(QHostAddress::Any, 4000)
{

server.cpp (部分)

#include "server.h"
#include "clientthread.h"

#include <stdlib.h>
Server(QHostAddress listenAddress, quint16 listenPort, QObject *parent = 0)
    : hostAddress(listenAddress), hostPort(listenPort), QTcpServer(parent)
{
}

上記のコードを更新しました。今コンパイラは不平を言います:

サーバーのコンストラクター定義の「listenAddress」の前に「)」が必要です。

4

1 に答える 1