Good day, I have send data Int,string ,and double, but i cun't recieve them correctly.
thys is mt button Qml where it have start the event:
CustomButton {
id: btnSalva
x: 0
color: qsTr("#ffffff")
text: "SALVA"
anchors.top: parent.top
anchors.topMargin: 50
anchors.right: parent.right
anchors.rightMargin: 50
onClicked: {
backend.connectClicked()
backend.sendUpdateRiparazione(3,txtCodice.text,txtPCosto.text,txtPPub.text);
}
}
CustomButton {
id: btnSalva
x: 0
color: qsTr("#ffffff")
text: "SALVA"
anchors.top: parent.top
anchors.topMargin: 50
anchors.right: parent.right
anchors.rightMargin: 50
onClicked: {
backend.connectClicked()
backend.sendUpdateRiparazione(3,txtCodice.text,txtPCosto.text,txtPPub.text);
}
}
To copy to clipboard, switch view to plain text mode
this is the metod that send at server:
void Backend::sendUpdateRiparazione(qint16 type,qint16 codice, double pCosto, double pPubblico)
{
//client->connect2host();
//out.setVersion(QDataStream::Qt_5_10);
//out <<qint16(0) << type << codice << pCosto << pPubblico ;
out << qint16(0);
out << (qint16)type;
out << (qint16)codice;
out << (double)pCosto;
out << (double)pPubblico;
// out << msg ;
out.device()->seek(0);
out << quint16(arrBlock.size() - sizeof(quint16));
client->tcpSocket->write(arrBlock);
}
void Backend::sendUpdateRiparazione(qint16 type,qint16 codice, double pCosto, double pPubblico)
{
//client->connect2host();
QByteArray arrBlock;
QDataStream out(&arrBlock, QIODevice::WriteOnly);
//out.setVersion(QDataStream::Qt_5_10);
//out <<qint16(0) << type << codice << pCosto << pPubblico ;
out << qint16(0);
out << (qint16)type;
out << (qint16)codice;
out << (double)pCosto;
out << (double)pPubblico;
// out << msg ;
out.device()->seek(0);
out << quint16(arrBlock.size() - sizeof(quint16));
client->tcpSocket->write(arrBlock);
}
To copy to clipboard, switch view to plain text mode
this is Server:
void ClientResearch::readClient()
{
QTcpSocket *clientSocket
= static_cast<QTcpSocket
*>
(sender
());
for (;;)
{
if (!m_nNextBlockSize)
{
if (clientSocket->bytesAvailable() < sizeof(quint16)) { break; }
in >> m_nNextBlockSize;
}
if (clientSocket->bytesAvailable() < m_nNextBlockSize) { break; }
qint16 type;
emit gotNewMesssage(str);
m_nNextBlockSize = 0;
in >> type ;
switch (type) {
case 1:if(type == 1){
in >> str;
sendToClient(clientSocket, str);
qDebug()<< "chiamata uno ";
break;
}
case 2:if(type == 2){
in >> str;
sendMag(clientSocket, str);
break;
}
case 3:if(type ==3){
qDebug()<< "chiamata tre ";
qint64 c_codice;
double p_prezzoCosto;
double p_prezzoPubblico;
in >> c_codice >> p_prezzoCosto >> p_prezzoPubblico;
qDebug() <<c_codice << p_prezzoCosto << p_prezzoPubblico <<"evviva";
updateRiparazione(c_codice,p_prezzoCosto,p_prezzoPubblico);
}
break;
}
}
}
void ClientResearch::readClient()
{
QTcpSocket *clientSocket = static_cast<QTcpSocket*>(sender());
QDataStream in(clientSocket);
for (;;)
{
if (!m_nNextBlockSize)
{
if (clientSocket->bytesAvailable() < sizeof(quint16)) { break; }
in >> m_nNextBlockSize;
}
if (clientSocket->bytesAvailable() < m_nNextBlockSize) { break; }
QString str;
qint16 type;
emit gotNewMesssage(str);
m_nNextBlockSize = 0;
in >> type ;
switch (type) {
case 1:if(type == 1){
in >> str;
sendToClient(clientSocket, str);
qDebug()<< "chiamata uno ";
break;
}
case 2:if(type == 2){
in >> str;
sendMag(clientSocket, str);
break;
}
case 3:if(type ==3){
qDebug()<< "chiamata tre ";
qint64 c_codice;
double p_prezzoCosto;
double p_prezzoPubblico;
in >> c_codice >> p_prezzoCosto >> p_prezzoPubblico;
qDebug() <<c_codice << p_prezzoCosto << p_prezzoPubblico <<"evviva";
updateRiparazione(c_codice,p_prezzoCosto,p_prezzoPubblico);
}
break;
}
}
}
To copy to clipboard, switch view to plain text mode
the data recived are these,the only variable correct is "type" codice should be 82253, p_prezzoCosto 3873,p_prezzoPubblico 9681
Cattura.JPG
Bookmarks