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. QFileDialog: Close the dialog box opened by getOpenFileName
Qt 6.11 is out! See what's new in the release blog

QFileDialog: Close the dialog box opened by getOpenFileName

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.3k Views 1 Watching
  • 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.
  • J Offline
    J Offline
    jmnemonik
    wrote on last edited by
    #1

    Hello all
    I need to programmatically close the dialog box opened by QFileDialog:getOpenFileName.

    I know the parent window of the dialog.
    This code not work(dialog box not close):
    @
    QList<QDialog*> widgets = findChildren<QDialog*>();
    QList<QDialog*>::iterator cur = widgets.begin();
    QList<QDialog*>::iterator end = widgets.end();
    for (;cur != end; ++cur)
    {
    (*cur)->setParent(NULL);
    (*cur)->reject();
    }
    @

    I use qt 4.7.4

    1 Reply Last reply
    0
    • P Offline
      P Offline
      pke62
      wrote on last edited by
      #2

      QDialog::reject () - hides the modal dialog and sets the result code to Rejected. It does not close the dialog.

      You may want to try either close() or done(int r).

      • Phil
      1 Reply Last reply
      0
      • J Offline
        J Offline
        jmnemonik
        wrote on last edited by
        #3

        In my version qt functions reject() and accept() call done(). Call close() not close window.

        QFileDialog:getOpenFileName opens native MS Windows dialog. If set flag DontUseNativeDialog reject() will close dialog window, but I need native window.

        Qt code does not provide feedback?:
        @
        QDialog modal_widget;
        modal_widget.setAttribute(Qt::WA_NoChildEventsForParent, true);
        modal_widget.setParent(args.parent, Qt::Window);
        //QApplicationPrivate::enterModal(&modal_widget);

        bool hideFiltersDetails = args.options & QFileDialog::HideNameFilterDetails;
        OPENFILENAME* ofn = qt_win_make_OFN(args.parent, args.selection,
                                            args.directory, args.caption,
                                            qt_win_filter(args.filter, hideFiltersDetails),
                                            QFileDialog::ExistingFile,
                                            args.options);
        if (idx)
            ofn->nFilterIndex = idx + 1;
        if (GetOpenFileName(ofn)) {
            result = QString::fromWCharArray(ofn->lpstrFile);
            selFilIdx = ofn->nFilterIndex;
        }
        qt_win_clean_up_OFN(&ofn);
        

        @

        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