Hi
I'd like to deliver the updated datastring every 20ms to the server on click. at the moment only one datastring is delivered on click.
I tried to set a loop in void MainWindow::ConnectToServer(), but it does not seem to work.
below is the affected part of the code

I would appreciate your help
thanks in advance



Qt Code:
  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent),
  3. ui(new Ui::MainWindow)
  4. {
  5. // Initialize
  6. p_MainThread = NULL;
  7. p_SensorThreadArr = NULL;
  8. p_TcpSocket = NULL;
  9.  
  10. // set GUI
  11. SetGUIDialogBox();
  12.  
  13. ///p_MainThread = new MainThread();
  14.  
  15. // ********************
  16. // Connect to Server
  17. // ********************
  18. p_TcpSocket = &tcpSocket;
  19. //connect(p_TcpSocket, SIGNAL(connected()), this, SLOT(SendRequest()));
  20. connect(p_TcpSocket, SIGNAL(connected()), this, SLOT(StartTransfer()));
  21. // Two Buttons
  22. [B] connect(searchButton, SIGNAL(clicked()), this, SLOT(ConnectToServer()));[/B]
  23. connect(stopButton, SIGNAL(clicked()), this, SLOT(StopSearch()));
  24.  
  25. // **********************
  26. // Connect GUI Dialog Box
  27. // **********************
  28. connect(p_TcpSocket, SIGNAL(disconnected()), this, SLOT(ConnectionClosedByServer()));
  29. connect(p_TcpSocket, SIGNAL(readyRead()), this, SLOT(UpdateTableWidget()));
  30. connect(p_TcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(Error()));
  31. }
  32.  
  33.  
  34. void MainWindow::ConnectToServer()
  35. {
  36. p_MainThread->start();
  37.  
  38. bool isRuning = true;
  39. while (isRuning == true)
  40. for (int Ind=0; Ind<5; Ind++)
  41. {
  42. qDebug( " connectToServer! " );
  43.  
  44. ////p_ClientDataSocket->ConnectToServer(address, port);
  45. quint16 port = 8888;
  46. QString address = "127.0.0.1";
  47. QHostAddress addr(address);
  48. p_TcpSocket->connectToHost(addr, port);
  49.  
  50. UpdateConnectionGUI();
  51. //sleep( 1 ); // Sleep xx ms
  52. }
  53.  
  54. }
  55.  
  56.  
  57. void MainWindow::StartTransfer()
  58. {
  59. // *********************************
  60. // read sensor data from all sensors
  61. // *********************************
  62. for (int Ind=0; Ind<m_SensorSum; Ind++)
  63. {
  64. QByteArray qBetyArray = p_SensorThreadArr[Ind]->GetSensorData();
  65.  
  66. // *****************************************
  67. // build client socket message as QByreArray
  68. // *****************************************
  69. // int sensorDataStatus = p_SensorThread->GetSensorDataStatus();
  70. // no updated sensor data
  71. // if (sensorDataStatus != 1)
  72. // return;
  73.  
  74. // *******************************************
  75. // send client socket message to server socket
  76. // *******************************************
  77. int len = qBetyArray.length();
  78. tcpSocket.write(qBetyArray, len);
  79. }
  80.  
  81. return;
  82. }
To copy to clipboard, switch view to plain text mode