myserver.cpp 554 B

1234567891011121314151617181920212223242526
  1. #include "myserver.h"
  2. MyServer::MyServer(QObject *parent) :
  3. QTcpServer(parent)
  4. {
  5. }
  6. void MyServer::StartServer()
  7. {
  8. if(!this->listen(QHostAddress::Any,1234))
  9. {
  10. qDebug() << "Could not start server";
  11. }
  12. else
  13. {
  14. qDebug() << "Listening...";
  15. }
  16. }
  17. void MyServer::incomingConnection(qintptr socketDescriptor)
  18. {
  19. qDebug() << socketDescriptor << " Connecting...";
  20. MyThread *thread = new MyThread(socketDescriptor, this);
  21. connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
  22. thread->start();
  23. }