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 make a filedialog modal in a console application

How to make a filedialog modal in a console application

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

    Hello forum,

    I wrote an application that has no GUI, just two filedialogs.
    The application performs three simple steps:

    • Reading data from a file
    • Manipulate data using some formula
    • Store the result into another (new) file

    To determine the two filenames the filedialogs are used. The little program works fine, but there is one spot of bother: The filedialogs can be set into the background. This is unconvienient for the user, because he has to search for the dialogs. To solve this problem I want to set the filedialogs to "modal", but I had no success with this.
    I tested several variants but without any reuslt. Here is a fragment of my code. In the comments are some variants that I tested.

    ...
    QFileDialog inputFileDlg(Q_NULLPTR, "File to open", "MyStartPath", "MyFiles (*.xyz)");

    //inputFileDlg.setWindowFlag(Qt::WindowStaysOnTopHint, true);
    //inputFileDlg.open();
    //inputFileDlg.setModal(true);
    //QString defaultFileName = inputFileDlg.getOpenFileName(Q_NULLPTR, "File to open", "MyStartPath", "MyFiles (*.xyz)");
    // Finish if the file dialog is terminated
    

    // if (defaultFileName == "")
    // {
    // return;
    // }

    if (inputFileDlg.exec() != QDialog::Accepted)
    {
        return;
    }
    

    //Proceed with data manipulation
    ...

    Does anyone have an idea?
    Thanks in advance.

    Best regards
    Christian.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      I think it needs a widget based parent to stay on top (of parent)
      A shell window wont do im afraid.
      But i could be wrong and someone knows a trick :)

      1 Reply Last reply
      3

      • Login

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