soleil
11th October 2011, 08:17
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
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// Initialize
p_MainThread = NULL;
p_SensorThreadArr = NULL;
p_TcpSocket = NULL;
// set GUI
SetGUIDialogBox();
///p_MainThread = new MainThread();
// ********************
// Connect to Server
// ********************
p_TcpSocket = &tcpSocket;
//connect(p_TcpSocket, SIGNAL(connected()), this, SLOT(SendRequest()));
connect(p_TcpSocket, SIGNAL(connected()), this, SLOT(StartTransfer()));
// Two Buttons
connect(searchButton, SIGNAL(clicked()), this, SLOT(ConnectToServer()));
connect(stopButton, SIGNAL(clicked()), this, SLOT(StopSearch()));
// **********************
// Connect GUI Dialog Box
// **********************
connect(p_TcpSocket, SIGNAL(disconnected()), this, SLOT(ConnectionClosedByServer()));
connect(p_TcpSocket, SIGNAL(readyRead()), this, SLOT(UpdateTableWidget()));
connect(p_TcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(Error()));
}
void MainWindow::ConnectToServer()
{
p_MainThread->start();
bool isRuning = true;
while (isRuning == true)
for (int Ind=0; Ind<5; Ind++)
{
qDebug( " connectToServer! " );
////p_ClientDataSocket->ConnectToServer(address, port);
quint16 port = 8888;
QString address = "127.0.0.1";
QHostAddress addr(address);
p_TcpSocket->connectToHost(addr, port);
UpdateConnectionGUI();
//sleep( 1 ); // Sleep xx ms
}
}
void MainWindow::StartTransfer()
{
// *********************************
// read sensor data from all sensors
// *********************************
for (int Ind=0; Ind<m_SensorSum; Ind++)
{
QByteArray qBetyArray = p_SensorThreadArr[Ind]->GetSensorData();
// *****************************************
// build client socket message as QByreArray
// *****************************************
// int sensorDataStatus = p_SensorThread->GetSensorDataStatus();
// no updated sensor data
// if (sensorDataStatus != 1)
// return;
// *******************************************
// send client socket message to server socket
// *******************************************
int len = qBetyArray.length();
tcpSocket.write(qBetyArray, len);
}
return;
}
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
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
// Initialize
p_MainThread = NULL;
p_SensorThreadArr = NULL;
p_TcpSocket = NULL;
// set GUI
SetGUIDialogBox();
///p_MainThread = new MainThread();
// ********************
// Connect to Server
// ********************
p_TcpSocket = &tcpSocket;
//connect(p_TcpSocket, SIGNAL(connected()), this, SLOT(SendRequest()));
connect(p_TcpSocket, SIGNAL(connected()), this, SLOT(StartTransfer()));
// Two Buttons
connect(searchButton, SIGNAL(clicked()), this, SLOT(ConnectToServer()));
connect(stopButton, SIGNAL(clicked()), this, SLOT(StopSearch()));
// **********************
// Connect GUI Dialog Box
// **********************
connect(p_TcpSocket, SIGNAL(disconnected()), this, SLOT(ConnectionClosedByServer()));
connect(p_TcpSocket, SIGNAL(readyRead()), this, SLOT(UpdateTableWidget()));
connect(p_TcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(Error()));
}
void MainWindow::ConnectToServer()
{
p_MainThread->start();
bool isRuning = true;
while (isRuning == true)
for (int Ind=0; Ind<5; Ind++)
{
qDebug( " connectToServer! " );
////p_ClientDataSocket->ConnectToServer(address, port);
quint16 port = 8888;
QString address = "127.0.0.1";
QHostAddress addr(address);
p_TcpSocket->connectToHost(addr, port);
UpdateConnectionGUI();
//sleep( 1 ); // Sleep xx ms
}
}
void MainWindow::StartTransfer()
{
// *********************************
// read sensor data from all sensors
// *********************************
for (int Ind=0; Ind<m_SensorSum; Ind++)
{
QByteArray qBetyArray = p_SensorThreadArr[Ind]->GetSensorData();
// *****************************************
// build client socket message as QByreArray
// *****************************************
// int sensorDataStatus = p_SensorThread->GetSensorDataStatus();
// no updated sensor data
// if (sensorDataStatus != 1)
// return;
// *******************************************
// send client socket message to server socket
// *******************************************
int len = qBetyArray.length();
tcpSocket.write(qBetyArray, len);
}
return;
}