Advertisement
PlotnikovPhilipp

Untitled

Mar 26th, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. #include <client.hpp>
  2.  
  3. using namespace Qt;
  4.  
  5. Client::Client(QLineEdit* pline1, QLineEdit* pline2, QObject* pointer) : QObject(pointer), sizeOfData(0) {
  6. name = pline1;
  7. password = pline2;
  8. pTcpSocket = new QTcpSocket(this);
  9. pTcpSocket->connectToHost("77.223.89.11", 2323);
  10. connect(pTcpSocket, SIGNAL(connected()), SLOT(slotConnected()));
  11. connect(pTcpSocket, SIGNAL(readyRead()), SLOT(slotReadyRead()));
  12. connect(pTcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(slotError(QAbstractSocket::SocketError)));
  13. }
  14.  
  15. void Client::slotReadyRead () {
  16. QDataStream in(pTcpSocket);
  17. in.setVersion(QDataStream::Qt_5_3);
  18. in>>sizeOfData;
  19. while(pTcpSocket->bytesAvailable() < sizeOfData) {
  20. pTcpSocket->waitForReadyRead();
  21. }
  22. if (!str[0].contains("Authorization")) {
  23. str.clear();
  24. in>>imgs;
  25. }
  26. else if (str[1] != "Signing up") {
  27. str.clear();
  28. in>>str;
  29. if (!str[0].isNull()) {
  30. QMessageBox::about(nullptr, "MuseumQuest", "Вы успешно вошли в свой аккаунт!");
  31. }
  32. else {
  33. QMessageBox::about(nullptr, "MuseumQuest", "Вы не зарегистрировались!");
  34. }
  35. }
  36. else {
  37. str.clear();
  38. in>>str;
  39. }
  40. }
  41.  
  42. void Client::slotError(QAbstractSocket::SocketError err) {
  43. QString strError = "Error: " + (err == QAbstractSocket::HostNotFoundError ? "The host was not fount." : err == QAbstractSocket::RemoteHostClosedError ? "The remote host is closed." : err == QAbstractSocket::ConnectionRefusedError ? "The connection was refused." : QString(pTcpSocket->errorString()));
  44. qDebug()<<strError;
  45. }
  46.  
  47. void Client::slotSendToServer() {
  48. QByteArray arrBlock;
  49. QDataStream out(&arrBlock, QIODevice::WriteOnly);
  50. out.setVersion(QDataStream::Qt_5_3);
  51. QMessageBox::about(nullptr, "MuseumQuest", "Hello");
  52. str << sender()->objectName();
  53. QString info = QString("SELECT \"Name\" FROM \"Authorization\" WHERE \"Name\" = '%1' AND \"password\" = '%2'").arg(name->text()).arg(password->text());
  54. out<<int(0)<<info;
  55. out.device()->seek(0);
  56. out << int(arrBlock.size() - sizeof(int));
  57. pTcpSocket->write(arrBlock);
  58. }
  59. void Client::slotConnected() {
  60. qDebug()<<"Received the connected() signal";
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement