当前位置:   article > 正文

QThread实现TCP通信的多线程实例_qt启动线程执行tcp接收数据

qt启动线程执行tcp接收数据

1、QTCreater4.10.1

2、

1、主函数:

  1. #include <QCoreApplication>
  2. #include<server.h>
  3. int main(int argc, char *argv[])
  4. {
  5. QCoreApplication a(argc, argv);
  6. //开启服务
  7. server s;
  8. s.startserver(520);
  9. return a.exec();
  10. }

2、server类:

  1. #ifndef SERVER_H
  2. #define SERVER_H
  3. #include <QObject>
  4. #include <QTcpServer>
  5. class server : public QTcpServer
  6. {
  7. Q_OBJECT
  8. public:
  9. explicit server(QTcpServer *parent = nullptr);
  10. signals:
  11. public slots:
  12. bool startserver(unsigned short port = 8888);
  13. void stopserver();
  14. protected:
  15. void incomingConnection(int socketDescriptor);
  16. };
  17. #endif // SERVER_H
  1. #include "server.h"
  2. #include <mythread.h>
  3. #include <QDebug>
  4. server::server(QTcpServer *parent) : QTcpServer(parent)
  5. {
  6. }
  7. bool server::startserver(unsigned short port)
  8. {
  9. if(this->isListening())
  10. {
  11. qDebug() << "s
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/187351?site
推荐阅读
相关标签
  

闽ICP备14008679号