Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to make a filedialog modal in a console application

    General and Desktop
    2
    2
    423
    Loading More Posts
    • 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
      Naitsirhc last edited by

      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 Reply Quote 0
      • mrjj
        mrjj Lifetime Qt Champion last edited by

        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 Reply Quote 3
        • First post
          Last post