Time for action – constructing the query
Whenever the button is pressed, the sendRequest()
slot is called:
void MainWindow::sendRequest() { if (m_reply != 0 && m_reply->isRunning()) m_reply->abort(); ui->result->clear();
In this slot, we first check whether there is an old request, which was stored in m_reply
, and if it is still running. If that is true
, we abort the old request as we are about to schedule a new one. Then, we also wipe out the result of the last request by calling QPlainTextEdit::clear()
on the text edit.
Next, we will construct the URL for the request. We can do this by composing the string by hand where we add the query parameters to the base URL similar to:
url = baseUrl + "?origin=" + ui->from->text() + "&...";
Besides the problem that this quickly becomes hard to read when we include multiple parameters, it is also rather error-prone. The values of the line edits have to be encoded to fit the criteria for a valid URL. For every user...