Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-49270

QUrl objects barely usable in QML

    XMLWordPrintable

Details

    Description

      Suppose I want to pass QUrl to my QML code, like so:

          QQmlEngine engine;
          engine.rootContext()->setContextProperty("contextUrl", QUrl{"http://google.com"});
          QQmlComponent component(&engine);
          component.setData(R"(
                            import QtQml 2.2
                            QtObject {
                                Component.onCompleted: {
                                    console.log("URL = " + contextUrl.scheme);
                                }
                            }
                            )", QUrl{});
          qDebug() << component.create();
      

      That does not work, as 'scheme' ends up undefined, as well as every other method that QUrl has, so one has to take URL as string, and use regexp to manipulate it, and that's quite painful and likely to result in bugs.

      It looks like in Qt 5.4.1, QV8Engine::fromVariant has special handling for QDateTime or for QRegexp, but not for QUrl. In git dev branch, the code has moved to QV4::ExecutionEngine::fromVariant, but there's no handling for QUrl either. As result, just QVariant is exported to QML, which toString as the only useful method.

      If would be really good if a custom wrapper for QUrl were created.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              vladimir.prus Vladimir Prus
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes