質問

#include <QApplication>
#include <QFileDialog>
#include <QDebug>

int main(int argc, char** argv){
    QApplication app(argc, argv);

    QFileDialog dlg;
    dlg.setAcceptMode(QFileDialog::AcceptSave);
    if (dlg.exec()) {
        qDebug() << dlg.selectedFiles();
    }
    return app.exec();
}

With this code we can can create QFileDialog. The problem is that it doesn't recoginize some special characters which can be typed in its "File name" entry:

1) For """ save button become disabled so I cant save file with name """

2) For "aaa it prints aaa

3) For \"aaa it again prints aaa

4) For aaaa"eee it prints eee

5) For \" save button is enabled but it does nothing when clicked.

I am using Linux. Does anyone konw the solution for this issue?

役に立ちましたか?

解決

The reason of such behavior could be that " character used as a file names separator in the QFileDialog's line edit. I.e. you can write something like "file1" "file2" to open multiple files. For better understanding on what is going on in this dialog, you can take a look in Qt sources, especially in QFileDialogPrivate::typedFiles() function (qfiledialog.cpp), where your input is split by ":

QStringList tokens = editText.split(QLatin1Char('\"'));
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top