0
#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..
    }
}

この状況を解決する方法は?ありがとう。

4

1 に答える 1

1

QSignalMapperを使用します。これにより、シグナルの送信者を識別できます。

于 2012-05-14T15:59:25.610 に答える