QFileDialog: Close the dialog box opened by getOpenFileName
-
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
-
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).
-
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);
@