void Data::deleteSubjects(const QList<int> &ids) { int n = ids.size(); if (n <= 0) return; if (this->m_modifyReply) delete this->m_modifyReply; QUrl url = QUrl("http://szektam2.byethost3.com/deleteSubjects.php"); PARAMS params; params.addQueryItem("username", Key::username()); params.addQueryItem("password", Key::password()); params.addQueryItem("n", QString::number(n)); for (int i = 0; i < n; ++i) { params.addQueryItem(QString("id%1").arg(i), QString::number(ids[i])); } QByteArray data; #if QT5 data.append(params.toString()); url.setQuery(params); #else data.append(params.encodedQuery()); #endif QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); this->m_modifyReply = this->m_manager->post(request, data); connect(this->m_modifyReply, SIGNAL(finished()), this, SLOT(getSubjects())); }
void Data::insertSubject(const QString &name, const QString &shortName) { if (this->m_insertReply) delete this->m_insertReply; QUrl url = QUrl("http://szektam2.byethost3.com/insertSubject.php"); PARAMS params; params.addQueryItem("username", Key::username()); params.addQueryItem("password", Key::password()); params.addQueryItem("name", name); params.addQueryItem("shortName", shortName); QByteArray data; #if QT5 data.append(params.toString()); url.setQuery(params); #else data.append(params.encodedQuery()); #endif QNetworkRequest request(url); request.setHeader(QNetworkRequest::ContentTypeHeader, "application/x-www-form-urlencoded"); this->m_insertReply = this->m_manager->post(request, data); connect(this->m_insertReply, SIGNAL(finished()), this, SLOT(getSubjects())); //connect(this->m_insertReply, SIGNAL(finished()), this, SLOT(readReady())); }
void MyServer::slotReadClient() { QTcpSocket* pClientSocket = (QTcpSocket*)sender(); QDataStream in(pClientSocket); in.setVersion(QDataStream::Qt_5_3); for(;;){ if(!nextBlockSize){ if(pClientSocket->bytesAvailable() < sizeof(quint32)) { break; } in >> nextBlockSize; } if(pClientSocket->bytesAvailable() < nextBlockSize) { break; } QString request; in >> request; QStringList req_param = request.split(" "); if(req_param.at(0) == "GETCURRENTVERSION") sendCurrVers(pClientSocket); if(req_param.at(0) == "GETSUBJECTS") sendArrayToClient(pClientSocket,getSubjects()); if(req_param.at(0) == "GETTHEMES") sendArrayToClient(pClientSocket,getThemes(req_param.at(1))); if(req_param.at(0) == "GETPICTURES") sendArrayToClient(pClientSocket,getPictures(req_param.at(1),req_param.at(2))); if(req_param.at(0) == "GETIMAGE") sendImageToClient(pClientSocket,getImage(req_param.at(1))); if(req_param.at(0) == "PUTSUBJECT"){ putSubject(req_param.at(1)); version++; } if(req_param.at(0) == "PUTTHEME"){ putTheme(req_param.at(1),req_param.at(2)); version++; } if(req_param.at(0) == "PUTIMAGE") { QImage img; in >> img; quint32 k = putImage(img,req_param.at(1),req_param.at(2), req_param.at(3)); version++; QList<QString> lst; lst << QString("%1").arg(k); sendArrayToClient(pClientSocket,lst); } if(req_param.at(0) == "DELETESUBJECT"){ deleteSubject(req_param.at(1)); version++; } if(req_param.at(0) == "DELETETHEME"){ deleteTheme(req_param.at(1),req_param.at(2)); version++; } if(req_param.at(0) == "DELETEIMAGE"){ deleteImage(req_param.at(1)); version++; } if(req_param.at(0) == "SWAPIMAGE"){ QImage img; in >> img; swapImage(img,req_param.at(1)); version++; }