I did so and It's Work )))
side Server:
{
// QBuffer buffer(&byteArray);
//buffer.open(QIODevice::WriteOnly);
query.prepare("SELECT Nbusta,costo,vendita FROM tabripa where Nbusta =(?)");
query.bindValue(0, str);
query.exec();
while (query.next()){
if(query.isValid()){
code = query.record().value("Nbusta").toInt();
pCost = query.record().value("costo").toDouble();
pPublic = query.record().value("vendita").toDouble();
stream << code <<pCost << pPublic ;
//buffer.close();
}
}
return socket->write(byteArray);
}
qint64 ServerThings::sendToClient(QTcpSocket *socket, const QString &str)
{
QByteArray byteArray;
// QBuffer buffer(&byteArray);
//buffer.open(QIODevice::WriteOnly);
QDataStream stream(&byteArray,QIODevice::WriteOnly);
QSqlQuery query;
query.prepare("SELECT Nbusta,costo,vendita FROM tabripa where Nbusta =(?)");
query.bindValue(0, str);
query.exec();
while (query.next()){
if(query.isValid()){
code = query.record().value("Nbusta").toInt();
pCost = query.record().value("costo").toDouble();
pPublic = query.record().value("vendita").toDouble();
stream << code <<pCost << pPublic ;
//buffer.close();
}
}
return socket->write(byteArray);
}
To copy to clipboard, switch view to plain text mode
side Client:
void ClientServices::readyRead()
{
int code = 0;
double pCost = 0;
double pPublic = 0;
in >> code >> pCost >> pPublic;
qDebug() << code << pCost << pPublic;
}
void ClientServices::readyRead()
{
QDataStream in(tcpSocket);//QtcpSocket
int code = 0;
double pCost = 0;
double pPublic = 0;
in >> code >> pCost >> pPublic;
qDebug() << code << pCost << pPublic;
}
To copy to clipboard, switch view to plain text mode
I did not use the Qbuffer because on the client I am not able to integrate it, but if I use it on the server side and on the client no the data is received the same. How does it look? We accept suggestions!
Bookmarks