Skip to content

Instantly share code, notes, and snippets.

@oppahero
Created November 9, 2018 05:07
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/2396264e4c50ce00ee7a238b6f68b08e to your computer and use it in GitHub Desktop.
Save oppahero/2396264e4c50ce00ee7a238b6f68b08e to your computer and use it in GitHub Desktop.
void Dialog::on_pushButton_ChooseFile_clicked()
{
//configurar el directorio de inicio a la ruta de inicio del usuario
QString homePath = QDir::homePath();
//Abre el dialogo y escoge el archivo. Obtenemos el path del archivo.
QString filePath = QFileDialog::getOpenFileName(this,tr("Open a file"),
homePath,tr("All files (*.*)"),NULL,QFileDialog::DontResolveSymlinks);
//Se obtiene el nombre del archivo
QString filename = filePath.section("/",-1);
//Si no se selecciona nada
if(filename.isEmpty())
return;
//Si se selecciono, confirmamos el envio
QMessageBox::StandardButton reply;
reply = QMessageBox::question(this,"Enviar archivo",tr("Quieres enviar \"%1\"?").arg(filename));
if (reply == QMessageBox::No )
return;
else{
emit envioArchivo();
sendFileToAll(filePath,filename);
//obtenemos la hora
QString currentTime = QTime::currentTime().toString("H:mm A");
//añadimos al chat grupa
ui->textEdit_ChatDisplay->append("<font color=\"DarkRed\"><b>"+username+
" ["+currentTime+"] ha enviado \""+filename+"\"</b></font>");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment