windows - Crash when calling getOpenFileName from QItemDelegate's custom editor -


prerequisites:

i have custom qitemdelegate creates custom editor treeview items. editor consists of qlineedit , qtoolbutton. button used open file dialog selecting file , placing it's path line edit. use call qfiledialog::getopenfilename open file dialog. dialog native windows file dialog (this important).

when editor created first time, works ok no matter how press button. after editor closed , reopened again first press on button results in crash. reason of crash custom editor gets deleted.

here code:

void ccustomeditor::on_runsetupbtn_clicked() {     auto qfilename = qfiledialog::getopenfilename(this,         "select application run",         qstring(),         "executable files (*.exe)");      if (qfilename.isempty())         return;      setcommandline(qdir::tonativeseparators(qfilename), m_qparameters); } 

i have made digging , found out calling winapi function getopenfilename results in same way: editor gets deleted (although crash doesn't happen). seems qt calls internally.

i have tracked down reason of why editor gets deleted , found out when getopenfilename called, active window changes , focus changes it. in first case focus moved treeview item, in second case moved editor itself! results in deletion of editor because of 'focus out' event.

it important situation doesn't happen if 'dontusenativedialog' flag set when file dialog created. therefore should bug in qt's window management between native windows , qt widgets.

as workaround of bug suggest following solution: before making call getopenfilename set focus button itself.

    m_pui->runsetupbtn->setfocus();      auto qfilename = qfiledialog::getopenfilename(this,             "select application run",             qstring(),             "executable files (*.exe)"); 

the other workaround use 'dontusenativedialog' flag, resulting file dialog doesn't native, in fact quite ugly. if has better solution, feel free share.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -