MainWindow
::MainWindow(QWidget *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
[B] connect(searchButton, SIGNAL(clicked()), this, SLOT(ConnectToServer()));[/B]
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;
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;
}
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
[B] connect(searchButton, SIGNAL(clicked()), this, SLOT(ConnectToServer()));[/B]
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;
}
To copy to clipboard, switch view to plain text mode
Bookmarks