のサブクラスでQtの機能のオーバーロード:私は<a href="http://doc.qt.io/archives/qt-4.7/qtcpserver.html" rel="nofollow">QTcpServer</a>のサブクラスを持ってQTcpServer
の.hファイル:
#ifndef GEOLISTENER_H
#define GEOLISTENER_H
#include <QTcpServer>
class GeoListener : public QTcpServer
{
Q_OBJECT
public:
explicit GeoListener(QObject *parent = 0);
bool listen(void);
signals:
public slots:
void handleConnection(void);
};
#endif // GEOLISTENER_H
た.cppファイル:
#include "geolistener.h"
#include <QDebug>
GeoListener::GeoListener(QObject *parent) :
QTcpServer(parent)
{
QObject::connect(this, SIGNAL(newConnection()),this, SLOT(handleConnection()));
}
bool GeoListener::listen(void)
{
bool ret;
ret = this->listen(QHostAddress::Any, 9871); //This function isn't found!
/* If something is to be done right after listen starts */
return ret;
}
void GeoListener::handleConnection(void) {
qDebug() << "got connection";
}
Qtフレームワークの基本クラスには、次の関数があります。
bool QTcpServer::listen (const QHostAddress & address = QHostAddress::Any, quint16 port = 0)
私はそれをlisten() - 関数でオーバーロードしました。私がそうするなら、私は上記の関数を呼び出すことはできません - 私の意見では、これはうまくいくはずです。なぜそれは働いていないのですか?何か案は?
私は自分のスキルをリフレッシュするために主にそれを行う - それは大学の単なるプロジェクトです。 ドキュメントに含まれていないベースクラスにlisten()関数があることは間違いありませんか?私はlisten()関数がlisten(const QHostAddress&address = QHostAddress :: Any、quint16 port = 0)関数を上書きする理由を理解できません。彼らは全く異なるパラメータを持っています。 – Herrbert
いいえ、それはまさにあなたが隠している署名 'listen(const QHostAddress&、quint)'を持つ関数です。 C++のこの「機能」は、標準(ref $ 3.3.10)に記述されています。 – Simone