2016-05-10 4 views

答えて

1

あなたはブロッキング方法を呼び出しています。そのメソッドが実行されている間、イベントループは実行できません。なぜなら、コールスタックの一番下にあるスロットで、スロットが戻ってくるのを待っているからです。これは、世界が非同期であるため、実際に起こっていることを反映しない同期的なコーディング方法です。そのようにコード化しないでください。

代わりに、ファイルダイアログが表示されていない間に設定してから、show()とし、QDialog::accepted()シグナルに接続されたスロットで目的のコードを実行する必要があります。

あなたはアウト設定を考慮してgetExistingDirectoryと同様に使用すてきな非同期ヘルパーを、持っている可能性があり:

void before() { 
    foo(); 
    auto dir = QFileDialog::getExistingDirectory(); // bad synchronous code 
    bar(dir); 
} 

void after() { 
    foo(); 
    withExistingDirectoryDo([this](const QDir & dir) { 
    bar(dir); 
    }, this); 
} 
+0

それは「QFileDialogをフラグを追加することで機能します:::

template <typename F> void withExistingDirectoryDo(F && fun, QObject * context = 0, QWidget * parent = 0, const QString & caption = QString(), const QString & dir = QString(), Options options = QFileDialog::ShowDirsOnly) { auto * dialog = new QFileDialog(parent); auto helper = [fun, dialog]{ fun(dialog->directory()); }; if (context) connect(dialog, &QDialog::accepted, context, helper); else connect(dialog, &QDialog::accepted, helper); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setOptions(options); dialog->setFileMode(QFileDialog::Directory); dialog->show(); } 

ここでは、コード変換ですDontUseNativeDialog "QString ldossier = QFileDialog :: getExistingDirectory(これは、"Sélectionnerundossier "、" C:/ PROJET/Qt/sauvegarde/texte/"、QFileDialog :: ShowDirsOnly | QFileDialog :: DontUseNativeDialog); – iboua

関連する問題