在Qt 5.12.0 版本中,用 QFileDialog 類來作文件選擇時候,發現當彈出對話框後,選擇完文件後,又彈出文件選擇對話框。函數
QFileDialog filedialog; filedialog.setAcceptMode(QFileDialog::AcceptOpen); filedialog.setFileMode(QFileDialog :: ExistingFiles); QStringList fileNames ; fileNames =filedialog.getOpenFileNames(); if( filedialog.exec() == QFileDialog::Accepted ) { qDebug()<<"get file "; QStringList fileNames ; fileNames =filedialog.getOpenFileNames(); for(int i=0;i<fileNames.length();i++) qDebug()<<fileNames[i]; }
經過 qDebug 打印得知 函數 :getOpenFileNames()有包含 exec()的做用code
QFileDialog filedialog; filedialog.setAcceptMode(QFileDialog::AcceptOpen); filedialog.setFileMode(QFileDialog :: ExistingFiles); QStringList fileNames ; fileNames =filedialog.getOpenFileNames(); for(int i=0;i<fileNames.length();i++) qDebug()<<fileNames[i];