Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for WebAssembly
  4. Problem using QFileDialog::saveFileContent on Chrome

Problem using QFileDialog::saveFileContent on Chrome

Scheduled Pinned Locked Moved Unsolved Qt for WebAssembly
3 Posts 2 Posters 1.2k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    rey1996
    wrote on last edited by
    #1

    Hello.
    When I try to use QFileDialog::saveFileContent in Qt for WebAssembly on Chrome the I get this error:

    Uncaught (in promise) DOMException: Failed to execute 'showSaveFilePicker' on 'Window': Must be handling a user gesture to show a file picker.

    It works perfectly on Mozilla Firefox.
    I'm using Qt 6.6.1. I've found some topics related to this problem, but it says it's been solved in Qt 6.5.
    I tried with, recently released, Qt 6.7 but the problem remains.

    Thank you.

    R 1 Reply Last reply
    0
    • R rey1996

      Hello.
      When I try to use QFileDialog::saveFileContent in Qt for WebAssembly on Chrome the I get this error:

      Uncaught (in promise) DOMException: Failed to execute 'showSaveFilePicker' on 'Window': Must be handling a user gesture to show a file picker.

      It works perfectly on Mozilla Firefox.
      I'm using Qt 6.6.1. I've found some topics related to this problem, but it says it's been solved in Qt 6.5.
      I tried with, recently released, Qt 6.7 but the problem remains.

      Thank you.

      R Offline
      R Offline
      ryan1969
      wrote on last edited by
      #2

      Hello, @rey1996

      I can see your post and i give you some information please see below and follow step-by-step.

      The error you’re encountering with QFileDialog::saveFileContent in Qt for WebAssembly on Chrome is related to the browser’s security restrictions. Chrome requires that the showSaveFilePicker function be triggered as a result of a user action, like a click event1. This is to ensure that the file picker dialog cannot be opened without direct user interaction, which is a security measure to prevent malicious scripts from simulating user actions.

      Here are some steps you can take to resolve this issue:

      • Ensure User Gesture: Make sure that the call to showSaveFilePicker is directly tied to a user gesture, such as a button click. Avoid calling it from asynchronous code that isn’t directly initiated by a user action.
      • Check for Promises: If you’re using promises or async functions, ensure that they do not break the user gesture context. Chrome’s security model considers certain asynchronous operations as breaking the user gesture context, which could lead to this error.
      • Review Code Structure: If you’re using classes or separate functions, make sure that the call to showSaveFilePicker doesn’t lose its context due to the code structure. The call needs to be made in a way that the browser can clearly recognize it as a result of a user action.
      • Update Browser: Ensure that your version of Chrome is up to date, as browser updates often include fixes for such issues.
      • Consult Qt Documentation: Review the Qt documentation for any updates or changes in how QFileDialog::saveFileContent should be used with the latest version of Qt.

      Remember, while Firefox may handle this differently, it’s important to adhere to Chrome’s requirements for user gestures to ensure compatibility.

      Best Regard,
      ryan1969

      @rey1996 ADP Vantage said in Problem using QFileDialog::saveFileContent on Chrome:

      Hello.
      When I try to use QFileDialog::saveFileContent in Qt for WebAssembly on Chrome the I get this error:
      Uncaught (in promise) DOMException: Failed to execute 'showSaveFilePicker' on 'Window': Must be handling a user gesture to show a file picker.
      It works perfectly on Mozilla Firefox.
      I'm using Qt 6.6.1. I've found some topics related to this problem, but it says it's been solved in Qt 6.5.
      I tried with, recently released, Qt 6.7 but the problem remains.
      Thank you.

      1 Reply Last reply
      1
      • R Offline
        R Offline
        rey1996
        wrote on last edited by
        #3

        Hello, @ryan1969.

        The problem was the saveFileContent function was being called at the end of a procedure that took a long time. I guess the browser could not link the function with the click event as you said. So I had to add another button for the user to click when the procedure finishes. This made everything work OK.

        Thank you for the help.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved