赞
踩
1、QTCreater4.10.1
2、
1、主函数:
- #include <QCoreApplication>
- #include<server.h>
-
- int main(int argc, char *argv[])
- {
- QCoreApplication a(argc, argv);
-
- //开启服务
- server s;
- s.startserver(520);
-
- return a.exec();
- }
2、server类:
- #ifndef SERVER_H
- #define SERVER_H
-
- #include <QObject>
- #include <QTcpServer>
-
- class server : public QTcpServer
- {
- Q_OBJECT
- public:
- explicit server(QTcpServer *parent = nullptr);
-
- signals:
-
- public slots:
- bool startserver(unsigned short port = 8888);
- void stopserver();
-
- protected:
- void incomingConnection(int socketDescriptor);
- };
-
- #endif // SERVER_H
- #include "server.h"
- #include <mythread.h>
- #include <QDebug>
-
- server::server(QTcpServer *parent) : QTcpServer(parent)
- {
-
- }
-
- bool server::startserver(unsigned short port)
- {
- if(this->isListening())
- {
- qDebug() << "s
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。