Time for action – Constructing the query

Whenever the button is pressed, the sendRequest() slot is called:

void MainWindow::sendRequest()
{
    if (m_reply != nullptr && 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 whether 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 the following:

// don't do this!QString ...

Get Game Programming using Qt 5 Beginner's Guide - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.