SGL
Signals | Public Member Functions | List of all members
GDownloader Class Reference

A GDownloader can download files and data over an internet connection. More...

#include "gdownloader.h"

Inheritance diagram for GDownloader:

Signals

void downloaded()
 This Qt signal fires when the data is done downloading. More...
 

Public Member Functions

 GDownloader()
 Creates a new downloader. More...
 
~GDownloader()
 Frees memory allocated internally by the downloader. More...
 
string downloadAsString(string url)
 Downloads the text contents of the given URL, returning them as a string. More...
 
void downloadToFile(string url, string file)
 Downloads the text contents of the given URL, saving it to the given output file. More...
 
string getErrorMessage() const
 Returns the last HTTP error message that occurred. More...
 
string getHeader(string name) const
 Returns the value of the given HTTP header for this URL request. More...
 
int getHttpStatusCode() const
 Returns the most recent HTTP status code, which may be a successful code (e.g. More...
 
string getUserAgent() const
 Returns the value of the HTTP "User-Agent" header for this URL request, or an empty string if the user agent has not been set. More...
 
bool hasError() const
 Returns true if the HTTP connection failed and had an error. More...
 
void httpGet(string url)
 Performs an HTTP GET request to the given URL. More...
 
void httpPost(string url)
 Performs an HTTP POST request to the given URL, submitting any headers and query parameters previously specified. More...
 
void setHeader(string name, string value)
 
void setUserAgent(string userAgent)
 

Detailed Description

A GDownloader can download files and data over an internet connection.

It can save the data to a file or return the data as a string.

Constructor & Destructor Documentation

◆ GDownloader()

Creates a new downloader.

◆ ~GDownloader()

~GDownloader ( )
virtual

Frees memory allocated internally by the downloader.

Member Function Documentation

◆ downloadAsString()

string downloadAsString ( string   url)

Downloads the text contents of the given URL, returning them as a string.

This method blocks until the data is finished downloading.

◆ downloaded

void downloaded ( )
signal

This Qt signal fires when the data is done downloading.

◆ downloadToFile()

void downloadToFile ( string   url,
string   file 
)

Downloads the text contents of the given URL, saving it to the given output file.

This method blocks until the data is finished downloading.

◆ getErrorMessage()

string getErrorMessage ( ) const

Returns the last HTTP error message that occurred.

If no HTTP errors have occurred, returns "".

◆ getHeader()

string getHeader ( string   name) const

Returns the value of the given HTTP header for this URL request.

If the given header is not defined, returns an empty string.

◆ getHttpStatusCode()

int getHttpStatusCode ( ) const

Returns the most recent HTTP status code, which may be a successful code (e.g.

200) or an error (e.g 404). If there is no HTTP status code to return, returns 0.

◆ getUserAgent()

string getUserAgent ( ) const

Returns the value of the HTTP "User-Agent" header for this URL request, or an empty string if the user agent has not been set.

◆ hasError()

bool hasError ( ) const

Returns true if the HTTP connection failed and had an error.

You can see what the error was by calling getErrorMessage.

◆ httpGet()

void httpGet ( string   url)

Performs an HTTP GET request to the given URL.

along with any headers previously specified.

◆ httpPost()

void httpPost ( string   url)

Performs an HTTP POST request to the given URL, submitting any headers and query parameters previously specified.

◆ setHeader()

void setHeader ( string   name,
string   value 
)

◆ setUserAgent()

void setUserAgent ( string   userAgent)