[Development] Compatability break in QUrl in Qt 4.8

shane.kearns at accenture.com shane.kearns at accenture.com
Tue Jan 31 12:57:01 CET 2012


> Fair enough.
>
> Other opinions around? Olivier has already said he's for reverting to
> the old
> 4.7 behaviour.
>
The documentation note about the dangers of constructing QUrl from QString was already there in 4.6 (at the bottom of the page)
However, QT_NO_URL_CAST_FROM_STRING is not defined by default, so there are no compiler errors or warnings when using unsafe construction.

So I'm ambivalent when it comes to C++ applications.

What has convinced me is the Qt Creator HTML5 app wizard generates this kind of unsafe code.
I would assume that many users of this app wizard are web developers with limited c++ skills, and in any case would expect the boilerplate generated by the SDK to be good.

So I am in favour of keeping the 4.7 behaviour in 4.x releases.
I'd also be in favour of making QT_NO_URL_CAST_FROM_STRING turned on by default in 5.x (i.e. you need to define QT_ALLOW_URL_CAST_FROM_STRING to allow those assignments)

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    Html5ApplicationViewer viewer;
    viewer.setOrientation(Html5ApplicationViewer::ScreenOrientationAuto);
    viewer.showExpanded();
    viewer.loadFile(QLatin1String("html/index.html")); // <-- relative path

    return app.exec();
}

QString Html5ApplicationViewerPrivate::adjustPath(const QString &path)
{
#ifdef Q_OS_UNIX
#ifdef Q_OS_MAC
    if (!QDir::isAbsolutePath(path))
        return QCoreApplication::applicationDirPath()
                + QLatin1String("/../Resources/") + path;
#else
    const QString pathInInstallDir = QCoreApplication::applicationDirPath()
        + QLatin1String("/../") + path;
    if (pathInInstallDir.contains(QLatin1String("opt"))
            && pathInInstallDir.contains(QLatin1String("bin"))
            && QFileInfo(pathInInstallDir).exists()) { // <-- condition is false on symbian
        return pathInInstallDir;
    }
#endif
#endif
    return path; // <-- path is unmodified
}

void Html5ApplicationViewer::loadFile(const QString &fileName)
{
    m_d->m_webView->setUrl(QUrl(Html5ApplicationViewerPrivate::adjustPath(fileName))); // <-- QT_NO_URL_CAST_FROM_STRING wouldn't have helped, but it should still be using QUrl::fromLocalFile
}

________________________________
Subject to local law, communications with Accenture and its affiliates including telephone calls and emails (including content), may be monitored by our systems for the purposes of security and the assessment of internal compliance with Accenture policy.
______________________________________________________________________________________

www.accenture.com




More information about the Development mailing list