Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. void Client:: Read(QString filename)
  2. {
  3.  
  4. QFile mfile(filename);
  5.  
  6. if(!mfile.open(QFile::ReadOnly | QFile::Text))
  7. {
  8. qDebug() << "Could Not Open File For Reading!";
  9. return;
  10. }
  11. QTextStream in(&mfile);
  12. //QByteArray ba;
  13. while (!in.atEnd()) {
  14.  
  15. line = in.readAll();
  16.  
  17. qDebug() << line;
  18.  
  19. }
  20.  
  21. mfile.close();
  22. }
  23.  
  24.  
  25. void Client::startTransfer()
  26. {
  27. QString mfilename ="/home/ddm/Desktop/client_24.08.12/ENV_1_M2000.csv";
  28. Read(mfilename);
  29. QByteArray ba = line.toLocal8Bit();
  30. c_str2 = ba.data();
  31. client.write(c_str2,2048);
  32. }
  33.  
  34. mythread.cpp
  35. void MyThread :: readyRead()
  36. {
  37. float array[ROWS][COLS];
  38.  
  39.  
  40. QByteArray Data = socket ->readAll();
  41. QString str(Data);
  42.  
  43. qDebug()<< socketDescriptor <<"Data in:" <<row<<Data;
  44.  
  45. QStringList tempCN = str.split("n");
  46. qDebug()<<"tempCN="<<tempCN;
  47. for(int i=0;i<40;i++)
  48. {
  49. QStringList tempCN1 = tempCN[i].split(",");
  50. qDebug()<<"tempCN1["<<i<<"]="<<tempCN1;
  51. array[i][0] = QString(tempCN1[0]).toFloat();
  52. array[i][1] = QString(tempCN1[1]).toFloat();
  53. array[i][2] = QString(tempCN1[2]).toFloat();
  54. array[i][3] = QString(tempCN1[3]).toFloat();
  55. array[i][4] = QString(tempCN1[4]).toFloat();
  56. array[i][5] = QString(tempCN1[5]).toFloat();
  57. }
  58. for(int i=0;i<40;i++)
  59. {
  60. for(int j=0;j<6;j++)
  61. {
  62.  
  63. qDebug()<<"array["<<i<<"]"<<"["<<j<<"]"<<array[i][j];
  64. }
  65. }
  66. row++;
  67. /* col++*/;
  68. }
  69. void MyThread :: disconnected()
  70. {
  71. qDebug()<< socketDescriptor <<"Disconnected";
  72. socket->deleteLater();
  73. exit(0);
  74. }
  75.  
  76. myserver.cpp
  77.  
  78. void MyServer :: StartServer()
  79. {
  80. if(!this->listen(QHostAddress::Any,1234))
  81. {
  82. qDebug() << "Could not start server";
  83. }
  84. else
  85. {
  86. qDebug() << "Listening...";
  87. }
  88. }
  89.  
  90. void MyServer :: incomingConnection(int socketDescriptor)
  91. {
  92. qDebug()<<socketDescriptor<<"Connecting...";
  93. MyThread *thread = new MyThread(socketDescriptor,this);
  94. connect(thread,SIGNAL(finished()),thread,SLOT(deleteLater()));
  95. thread ->start();
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement