Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to open an asynchronous application modal file dialog

How to open an asynchronous application modal file dialog

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 503 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.
  • K Offline
    K Offline
    Kerndog73
    wrote on last edited by Kerndog73
    #1

    It seems like I can't do this without compromise. I'm trying to open the dialog like this:

    auto *dialog = new QFileDialog;
    dialog->setAttribute(Qt::WA_DeleteOnClose);
    dialog->setAcceptMode(QFileDialog::AcceptOpen);
    dialog->setNameFilter("*.png");
    dialog->setFileMode(QFileDialog::ExistingFile);
    dialog->setDirectory("directory");
    CONNECT(dialog, fileSelected, this, openFile);
    dialog->open();
    

    The dialog doesn't appear. Am I doing something wrong?

    If I use show() then this works but then I have another problem. Setting the directory before calling show() doesn't set the directory! So I have to set the directory after showing the dialog but then the user sees the dialog changing directory. There's a flicker where the dialog is changing directory. So here's the code that sort of works:

    // ...
    dialog->show();
    dialog->setDirectory("directory");
    

    I can also use exec() instead of show() that the lets me set the directory before showing the dialog like this:

    // ...
    dialog->setDirectory("directory");
    dialog->exec();
    

    I was under the impression that synchronous dialogs were bad and that I should use asynchronous dialogs instead. That's what the docs say. What could cause open() to just not do anything?

    VRoninV 1 Reply Last reply
    0
    • K Kerndog73

      It seems like I can't do this without compromise. I'm trying to open the dialog like this:

      auto *dialog = new QFileDialog;
      dialog->setAttribute(Qt::WA_DeleteOnClose);
      dialog->setAcceptMode(QFileDialog::AcceptOpen);
      dialog->setNameFilter("*.png");
      dialog->setFileMode(QFileDialog::ExistingFile);
      dialog->setDirectory("directory");
      CONNECT(dialog, fileSelected, this, openFile);
      dialog->open();
      

      The dialog doesn't appear. Am I doing something wrong?

      If I use show() then this works but then I have another problem. Setting the directory before calling show() doesn't set the directory! So I have to set the directory after showing the dialog but then the user sees the dialog changing directory. There's a flicker where the dialog is changing directory. So here's the code that sort of works:

      // ...
      dialog->show();
      dialog->setDirectory("directory");
      

      I can also use exec() instead of show() that the lets me set the directory before showing the dialog like this:

      // ...
      dialog->setDirectory("directory");
      dialog->exec();
      

      I was under the impression that synchronous dialogs were bad and that I should use asynchronous dialogs instead. That's what the docs say. What could cause open() to just not do anything?

      VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      @Kerndog73 said in How to open an asynchronous application modal file dialog:

      The dialog doesn't appear

      Are you sure? open() does nothing but setting the modality of the window and then calls show() so it's strange that it doesn't work

      I was under the impression that synchronous dialogs were bad and that I should use asynchronous dialogs instead.

      Kinda... the mentioned "bug" is illustrated in this article. Strictly speaking it's better to use async even for modal dialogs but the downsides are performance and some very fringe case crash so I wouldn't be too worried about using exec() if it achieves what you want

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      2

      • Login

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