How to make a method send a signal and wait for the slot before returning?
<p>I have a class <code>ConnectionManager</code> with method <code>get_wifi_ssids()</code> that must return a list of SSIDs. The problem is that to get those SSIDs signals and slots need to be used, but I can't figure out a way to retrieve that information without first exiting the method.</p>

<p>Here is the hierarchy of the classes used from lowest-level to highest.</p>

<pre><code>/** Controls wireless network card by commanding a software component "connman" via DBus. */
class WifiController : QObject {
Q_OBJECT

public:

    void scan();
}

/** Low level interface to network interfaces. */
class NetworkController : QObject {
    Q_OBJECT

public:

    void scan_for_wifi() {
        wifi_controller.scan();
        // When scan is finished it sends the
        // NetworkTechnology::scanFinished signal.
    }

    // Gets info from cache. This cache is updated when a `scan()` happens.
    QList&lt;AccessPointInfo&gt; get_available_access_points;

private:
    WifiController wifi_controller;
}

/** High level interface to network interfaces. */
class ConnectionManager {
public:
    QList&lt;QString&gt; get_wifi_ssids() {
        netCtrlr.scan();
        // PROBLEM HERE: How do I wait for the `scanFinished` signal here, then
        // continue execution and return the SSIDs from the recently-updated
        // cache?

        QList&lt;AccessPointInfo&gt; APs { netCtrlr.get_available_access_points() };
        QList&lt;QSitrng&gt; ssids { parseAPInfo(APs) };
        return ssids;
    }

private:
    NetworkController netCtrlr;
}
</code></pre>

<p>The entirety of my application is in a single thread. "connman" is commanded by <code>WifiConroller</code> via DBus, and it is a separate process so obviously in a separate thread. The GUI runs in a separate process and my app communicates with it via DBus.</p>

<p>A <code>QEventLoop</code> is a bad solution because it's not meant to be used in production and is more of a hack, according to the comments in <a href="https://stackoverflow.com/a/3556525/797744">this answer</a>.</p>