[英]In the Qt how to open QFileDialog::getOpenFileNames in user home
I'm using Qt QFileDialog::getSaveFileName and QFileDialog::getOpenFileNames for the user to select where to save files and what files to open in my app. 我正在使用Qt QFileDialog :: getSaveFileName和QFileDialog :: getOpenFileNames让用户选择保存文件的位置以及在我的应用程序中打开的文件。
The third parameter of this function is the path where you want the window to open by default. 此函数的第三个参数是您希望窗口默认打开的路径。 In linux, How can I get the dialog to open in the user home, and in windows how can I get the dialog to open in the user user folder in win 7 or in 'My Documents' in win xp?
在linux中,如何在用户主页中打开对话框,在Windows中如何在win 7中的用户用户文件夹或win xp中的“我的文档”中打开对话框?
Currently I'm using the dialog like this: QFileDialog::getOpenFileNames(this, "Select a file to open...", HOME);
目前我正在使用这样的对话框:
QFileDialog::getOpenFileNames(this, "Select a file to open...", HOME);
where HOME is a preprocessor macro that in UNIX is ~ and in windows is C:\\ 其中HOME是预处理器宏,在UNIX中是〜并且在Windows中是C:\\
The Unix one does not work and opens the dialog in the same folder where the binary is. Unix的工作不起作用,并在二进制文件所在的同一文件夹中打开对话框。
Also if you want to apply a filter on existing files, you can try this: 此外,如果要对现有文件应用过滤器,可以尝试以下操作:
QString filter = "File Description (*.extention)";
// For example: "Mpeg Layer 3 music files (*.mp3)"
QFileDialog::getOpenFileName(this, "Select a file...", QDir::homePath(), filter);
And then once user selected a file, absolute address of that file is returned by QFileDialog::getOpenFileName
function. 然后,一旦用户选择了一个文件,
QFileDialog::getOpenFileName
函数就会返回该文件的绝对地址。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.