The downloadfile() function below connects a finished() reply my function writefile(). I want to have the downloadfile() return an int if it completes correctly, including the writefile(). But I don't know how to have the writefile() return an int to my downloadfile() or the function calling my download file, but I don't know how to put that int into a variable, since it is called through a connect() function and not explicitly within a function. How can I get the return from the writefile() to be part either the downloadfile() or the function that calls the downloadfile().

Here is the code:
Qt Code:
  1. int MainWindow::downloadfile(std::string address, std::string filename){
  2. /*takes address from the lineedit, puts it in url, sends request and connects
  3.   Puts the address in class variable address, then links signal readyread
  4.   writetofile, then writefile takes class variable
  5.   */
  6. filenamehold = filename.c_str();
  7. QString tempurl = address.c_str();
  8. QUrl url(tempurl);
  9. reply = manager.get(QNetworkRequest(url));
  10. connect(reply, SIGNAL(finished()), this, SLOT(writefile()));
  11. ui->label_5->setText("Downloading...");
  12. }
  13.  
  14. //function to write into the file after the finished slot is called
  15. int MainWindow::writefile(){
  16. //opens the file and checks to see that it is open, then writes
  17. //info into the file and sets label to done.
  18. file = new QFile(filenamehold);
  19. if (file->open(QIODevice::WriteOnly)){
  20. file->write(reply->readAll());
  21. ui->label_5->setText("Complete!");
  22. return 1;
  23. }
  24.  
  25. //checks for errors and display's if they exist
  26. if (reply->error()){
  27. ui->label_5->setText(reply->errorString());
  28. }
  29.  
  30. return 0;
  31. file->close();
  32. reply->deleteLater();
  33. }
To copy to clipboard, switch view to plain text mode