06 progressBar->hide();
07 }
Закрытая функция
01 void TripPlanner::stopSearch()
02 {
03 statusLabel->setText(tr("Search stopped"));
04 closeConnection();
05 }
Слот
01 void TripPlanner::connectionClosedByServer()
02 {
03 if (nextBlockSize != 0xFFFF)
04 statusLabel->setText(tr("Error: Connection closed by server" ));
05 closeConnection();
06 }
Слот
01 void TripPlanner::error()
02 {
03 statusLabel->setText(tcpSocket.errorString());
04 closeConnection();
05 }
Слот
На этом завершается рассмотрение класса
01 int main(int argc, char *argv[])
02 {
03 QApplication app(argc, argv);
04 TripPlanner tripPlanner;
05 tripPlanner.show();
06 return app.exec();
07 }
Теперь давайте реализуем сервер. Сервер состоит из двух классов:
01 class TripServer : public QTcpServer
02 {
03 Q_OBJECT
04 public:
05 TripServer(QObject *parent = 0);
06 private:
07 void incomingConnection(int socketId);
08 };
Класс
01 TripServer::TripServer(QObject *parent)
02 : QTcpServer (parent)
03 {
04 }
Конструктор
01 void TripServer::incomingConnection(int socketId)
02 {
03 ClientSocket *socket = new ClientSocket(this);
04 socket->setSocketDescriptor(socketId);
05 }
В функции
01 class ClientSocket : public QTcpSocket
02 {
03 Q_OBJECT
04 public:
05 ClientSocket(QObject *parent = 0);
06 private slots:
07 void readClient();
08 private:
09 void generateRandomTrip(const QString &from, const QString &to,
10 const QDate &date, const QTime &time);
11 quint16 nextBlockSize;
12 };