i want program browse button qt opens standard find file dialog. if user enters new file name in dialog want create file. if file exists want open it.
i have function given string make decision. however, qfiledialog::getopenfilename
shows user error if file doesn't exist, , qfiledialog::getsavefilename
asks user confirmation overwrite file if exist (which wouldn't anyways, should not showed).
is there qt standard implemented meet need without having create custom class iheriting qfiledialog
or resorting hairy situation?
here current working code, undesired behavior...
void login::browsefile() { qstring file = ui->txtfile->text(); if (file.isempty()) { file = qdir::homepath(); } file = qfiledialog::getopenfilename(this, tr("select monage database"), file, tr("database files (*.db)")); if (!file.isempty()) { opendb(file); } }
google failed me, few more minutes scrutinizing docs, , found this:
qfiledialog::dontconfirmoverwrite 0x00000004 don't ask confirmation if existing file selected. default confirmation requested.
i able use getsavefilename
achieve functionality desired. had specify option selectedfilter
, passed default 0
.
modified code:
void login::browsefile() { qstring file = ui->txtfile->text(); if (file.isempty()) { file = qdir::homepath(); } file = qfiledialog::getsavefilename(this, tr("select monage database"), file, tr("database files (*.db)"), 0, qfiledialog::dontconfirmoverwrite); if (!file.isempty()) { opendb(file); } }