Logo Search packages:      
Sourcecode: qt4-x11 version File versions  Download package

QUrl QUrl::resolved ( const QUrl relative  )  const

Returns the result of the merge of this URL with relative. This URL is used as a base to convert relative to an absolute URL.

If relative is not a relative URL, this function will return relative directly. Otherwise, the paths of the two URLs are merged, and the new URL returned has the scheme and authority of the base URL, but with the merged path, as in the following example:

         QUrl baseUrl("http://www.trolltech.com/support");
         QUrl relativeUrl("../products/solutions");
         qDebug(baseUrl.resolved(relativeUrl).toString());
         // prints "http://www.trolltech.com/products/solutions"

Calling resolved() with ".." returns a QUrl whose directory is one level higher than the original. Similarly, calling resolved() with "../.." removes two levels from the path. If relative is "/", the path becomes "/".

See also:
isRelative()

Definition at line 4279 of file qurl.cpp.

References d, setAuthority(), setEncodedQuery(), setFragment(), setPath(), and setScheme().

Referenced by QTextBrowser::loadResource(), and QTextBrowser::mouseMoveEvent().

{
    if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();

    QUrl r(relative), t;

    // be non strict and allow scheme in relative url
    if (r.scheme() == d->scheme)
        r.setScheme(QString());

    if (!r.scheme().isEmpty()) {
        t.setScheme(r.scheme());
        t.setAuthority(r.authority());
        t.setPath(r.path());
        t.d->path = QUrlPrivate::removeDotsFromPath(t.d->path);
        t.setEncodedQuery(r.encodedQuery());
    } else {
        if (!r.authority().isEmpty()) {
            t.setAuthority(r.authority());
            t.setPath(r.path());
            t.d->path = QUrlPrivate::removeDotsFromPath(t.d->path);
            t.setEncodedQuery(r.encodedQuery());
        } else {
            if (r.path().isEmpty()) {
                t.setPath(d->path);
                if (!r.encodedQuery().isEmpty())
                    t.setEncodedQuery(r.encodedQuery());
                else
                    t.setEncodedQuery(d->query);
            } else {
                if (r.path().startsWith(QLatin1Char('/'))) {
                    t.setPath(r.path());
                    t.d->path = QUrlPrivate::removeDotsFromPath(t.d->path);
                } else {
                    t.setPath(d->mergePaths(r.path()));
                    t.d->path = QUrlPrivate::removeDotsFromPath(t.d->path);
                }
                t.setEncodedQuery(r.encodedQuery());
            }
            t.setAuthority(d->authority());
        }
        t.setScheme(d->scheme);
    }
    t.setFragment(r.fragment());

    return t;
}


Generated by  Doxygen 1.6.0   Back to index