Skip to content

Instantly share code, notes, and snippets.

@oppahero
Created November 9, 2018 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oppahero/95ad277d9256c83c4efc0ae96b361fcb to your computer and use it in GitHub Desktop.
Save oppahero/95ad277d9256c83c4efc0ae96b361fcb to your computer and use it in GitHub Desktop.
void Server::on_client_fileSend(QString uname,QString filename,QByteArray dataOfFile){
ClientThread* client = (ClientThread*)sender();
QString currentTime = QTime::currentTime().toString("H:mm A/");
QString command = "/fileAll:"+currentTime + uname + " : " + filename + "\n";
QString filePath;
//Si no esta la carpeta creada, la crea.
if(!QDir("Documentos_Servidor").exists()){
qDebug() << "No esta creada la carpeta";
QDir().mkdir("Documentos_Servidor");
}
filePath ="Documentos_Servidor";
//Crea el archivo
QFile outFile(filePath+"/"+filename);
lastFileGroup = filePath + "/" + filename;
//Lo abre
if(!outFile.open(QIODevice::WriteOnly)){
qDebug() << "Error al intentar abrir el archivo";
return;
}
//escribe el contenido del ByteArray en el archivo y lo cierra
outFile.write(dataOfFile);
outFile.close();
this->sendDataFileToAll(command,dataOfFile,client);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment