Results 1 to 6 of 6

Thread: QWebEngine file chooser return value on cancel

  1. #1
    Join Date
    Nov 2008
    Posts
    178
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QWebEngine file chooser return value on cancel

    All,

    Using QWebEngine under Linux. When the upload button is clicked on the Web page a file chooser dialog pops up as expected. It doesn't look like the other file choosers on the platform, so I assume the Chromium code is providing its own. Since I cannot get a console and we are locked at 5.4, I was wondering if anyone knew what the embedded chrome file chooser returns (if anything) when a cancel is pressed. Is there per chance a signal which gets fired out to my application? What does it send to the Web page?

    The Webcontent developers have something which works on most platforms, except this one, but the lack of debug makes this a PITA. When we cancel out of the dialog the Web page gray screens out, since it is frameless and fullscreen, not much to see. It "acts like" the url is getting cleared, which may be a side effect/but with the file chooser, making the assumption it was being used for a local file load to the main browser when the cancel button is hit.

    I'm going to turn on the frame and stuff so I can see if the url is really getting cleared, but knowing that won't really assist in a work around. At an application level I need to determine when the file chooser has been launched and when it was cancelled so I can save the current URL and reload it.

    Thanks,

  2. #2
    Join Date
    Nov 2008
    Posts
    178
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebEngine file chooser return value on cancel

    This appears to be a bug in the file chooser used by QWebEngine. Chromium uses the standard system file selector and behaves as expected with the web content. The file chooser provided by QWebEngine is calling the watcher twice. First with a null and the second time with a valid empty object so the watcher does nothing. Removing the watcher completely causes the same grey/gray screen because the removal of the dialog causes something bad to happen to the actual page content, but not the url.

    Have to do more debugging tomorrow after some sleep. Definitely a problem with this ported chromium code though.

  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,359
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebEngine file chooser return value on cancel

    Maybe you can reimplement http://doc.qt.io/qt-5/qwebenginepage.html#chooseFiles and show your own file dialog?

    Cheers,
    _

  4. #4
    Join Date
    Nov 2008
    Posts
    178
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebEngine file chooser return value on cancel

    Quote Originally Posted by anda_skoa View Post
    Maybe you can reimplement http://doc.qt.io/qt-5/qwebenginepage.html#chooseFiles and show your own file dialog?

    Cheers,
    _
    Since I'm not a JSon or Angular coder it took a bit to diagnose, but, every other browser file chooser does not return on cancel. This one returns first a NULL, then an empty files[]. The "quick fix" is/was to work around the bogus return in the code. Yes, you are correct. The proper fix would be to use the OS provided file chooser like other applications on the platform. That said, I'm a bit tired of going to bed at midnight or later then being back to work by 8am. There is sooo much else to get done before the next release in just a few days.

  5. #5
    Join Date
    Nov 2008
    Posts
    178
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QWebEngine file chooser return value on cancel

    Quote Originally Posted by anda_skoa View Post
    Maybe you can reimplement http://doc.qt.io/qt-5/qwebenginepage.html#chooseFiles and show your own file dialog?

    Cheers,
    _

    Ultimately I had to derive a class and patch the bug (because we aren't building Qt from scratch). The fix appears below:

    Qt Code:
    1. // Code stolen from QWebEnginePage so we could FIX it. Browser had real problems when a stringlist containing an
    2. // empty list returned.
    3. QStringList MyWebEnginePage::chooseFiles(FileSelectionMode mode, const QStringList &oldFiles, const QStringList &acceptedMimeTypes)
    4. {
    5. // FIXME: Should we expose this in QWebPage's API ? Right now it is very open and can contain a mix and match of file extensions $
    6. // can work with) and mimetypes ranging from text/plain or images/* to application/vnd.openxmlformats-officedocument.spreadsheetm$
    7. Q_UNUSED(acceptedMimeTypes);
    8. QStringList emptyList;
    9. switch (static_cast<WebContentsAdapterClient::FileChooserMode>(mode)) {
    10. case WebContentsAdapterClient::OpenMultiple:
    11. ret = QFileDialog::getOpenFileNames(view(), QString());
    12. break;
    13. // Chromium extension, not exposed as part of the public API for now.
    14. case WebContentsAdapterClient::UploadFolder:
    15. ret << QFileDialog::getExistingDirectory(view(), tr("Select folder to upload")) + QLatin1Char('/');
    16. break;
    17. case WebContentsAdapterClient::Save:
    18. ret << QFileDialog::getSaveFileName(view(), QString(), (QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) + oldFiles.first()));
    19. break;
    20. default:
    21. case WebContentsAdapterClient::Open:
    22. ret << QFileDialog::getOpenFileName(view(), QString(), oldFiles.first());
    23. break;
    24. }
    25.  
    26. // Needed fix
    27. if (ret.count() > 0)
    28. {
    29. if (ret[0].trimmed().length() > 0)
    30. return ret;
    31. }
    32.  
    33. return emptyList;
    34.  
    35. }
    To copy to clipboard, switch view to plain text mode 

    Returning a QStringList with an empty string in it hoses things up. Returning an empty list makes them work just fine. At some point I need to log a bug.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,359
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QWebEngine file chooser return value on cancel

    Right, this is what I was suggeting

    Cheers,
    _

Similar Threads

  1. Did Javascript Bridge support for QWebEngine make it into 5.5?
    By RolandHughes in forum Qt Programming
    Replies: 10
    Last Post: 25th June 2015, 17:34
  2. QWebEngine: Ram size increases when load video
    By pipi in forum Qt Programming
    Replies: 0
    Last Post: 2nd March 2015, 09:07
  3. Replies: 1
    Last Post: 2nd January 2013, 09:48
  4. Replies: 2
    Last Post: 12th October 2010, 20:50
  5. Cancel last user ever
    By 1111 in forum Qt Programming
    Replies: 2
    Last Post: 28th November 2008, 17:26

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.