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

[REG 4->5] URL in QFileOpenEvent on OS X is getting a "file" scheme

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • None
    • 5.3.1
    • QPA
    • None
    • OS X 10.6 and 10.9
    • macOS

    Description

      In Qt 5, a URL beginning with "<scheme>://" as typed into a web browser is stripped of its second slash, becoming "<scheme>:/", by the time it is delivered in association with a QFileOpenEvent to the QApplication registered as the handler for the protocol.

      To reproduce, start with an example that inherits QApplication, e.g., qtbase/examples/widgets/widgets/tablet. Insert the following within the body of TabletApplication::event(Qevent *event) in tabletapplication.cpp:

           if (event->type() == QEvent::FileOpen)
           { 
               qDebug() << "fileOpen event:  url is" << static_cast<QFileOpenEvent *>(event)->url();
               qDebug() << "fileOpen event: file is" << static_cast<QFileOpenEvent *>(event)->file();
           }
      

      Build the project.

      Now insert the following within tablet.app/Contents/Info.plist to register tablet.app as the handler for the custom "tablet-example-qt5" protocol:

       	<key>CFBundleURLTypes</key>
       	<array>
       		<dict>
       			<key>CFBundleURLName</key>
       			<string>Tablet Example</string>
       			<key>CFBundleURLSchemes</key>
       			<array>
       				<string>tablet-example-qt5</string>
       			</array>
       		</dict>
       	</array>
      

      If necessary, copy tablet.app to a new location (e.g., ~/Desktop) to force an update of the Launch Services database and force the registration to take effect immediately.

      Within a web browser (e.g., Safari), enter URL

      tablet-example-qt5://testurl

      The tablet application is launched and prints console messages:

      fileOpen event:  url is  QUrl( "file:tablet-example-qt5:/testurl" ) 
      fileOpen event: file is "tablet-example-qt5:/testurl"
      

      Note that the second slash from the "://" in the original URL has been stripped. (In fact, no matter how many slashes you type following the colon, all slashes beyond the first are stripped.)

      This is a regression from Qt 4. Following a similar procedure at Qt 4.8.6 yields console messages:

      fileOpen event:  url is  QUrl( "tablet-example-qt4://testurl" )
      fileOpen event: file is ""
      

      Related: QTBUG-34801: Qt5 Mac application cannot handle custom url scheme

      Attachments

        Issue Links

          For Gerrit Dashboard: QTBUG-39972
          # Subject Branch Project Status CR V

          Activity

            People

              sorvig Morten Sørvig
              mkegan Melissa Egan
              Votes:
              4 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes