Dewsworld
Dewsworld

Reputation: 14033

Qt multiple webview handling with single slot

#include <QWebView>
#include <QObject>

class MyWebview  : public QObject {
    Q_OBJECT

private:
    QWebView *v1, *v2, *v3, *v4;

public:
    MyWebview() {
        v1 = new QWebView(0);
        v2 = new QWebView(0);
        v3 = new QWebView(0);
        v4 = new QWebView(0);

        v1->load(QUrl("http://google.com"));
        v2->load(QUrl("http://facebook.com"));
        v3->load(QUrl("http://bing.com"));
        v4->load(QUrl("http://twitter.com"));

        connect(v1, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
        connect(v2, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
        connect(v3, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
        connect(v4, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
    }

public slots:
    void    MyWebview::finished(bool ok)    {   // [ SLOT ]
        switch( /**/ ) {
            case /*if it is v1*/:
            disconnect(v1, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
            break;

        case /*if it is v2*/:
            disconnect(v2, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
            break;

        case /*if it is v3*/:
            disconnect(v3, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
            break;

        case /*if it is v3*/:
            disconnect(v4, SIGNAL(loadFinished(bool)), this, SLOT(finished(bool)));
            break;
        }

        // do something..
    }
}

How to solve this situation? Thanks.

Upvotes: 0

Views: 408

Answers (1)

Anthony
Anthony

Reputation: 8788

Use a QSignalMapper. It allows you to identify the sender of a signal.

Upvotes: 1

Related Questions