QSettings - 文件选择器应该记住最后一个目录
我从某个位置上传文件,然后下一次上传必须指向上次上传的位置。 我如何使用 QSettings 来完成此任务?
I upload a file from a location, then the next upload has to point the last uploaded location.
How can I accomplish thus using QSettings
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在使用
QSettings
之前,我建议在您的main()
中设置一些有关您的应用程序和公司的信息,这些信息QSettings
将be using :然后,当使用
QFile::getOpenFileName()
(例如)选择文件时,您可以从QSetting
的键读取最后一个目录。然后,如果所选文件有效,您可以存储/更新密钥的内容:Before using
QSettings
, I would suggest, in yourmain()
to set a few informations about your application and your company, informations thatQSettings
will be using :Then, when selecting a file with
QFile::getOpenFileName()
(for instance), you can read from a key ofQSetting
the last directory. Then, if the selected file is valid, you can store/update the content of the key :如果您正在谈论 QFileDialog(),您可以在构造函数中指定起始目录:
或者您可以使用像这样的辅助函数之一,它也允许您指定起始目录:
每次使用后,存储原来的目录路径选择并在下次显示对话框时使用它。
If you are talking about QFileDialog() you can specify the starting directory in the constructor:
Or you can use one of the helper functions like this one which also allow you to specify the starting directory:
After each use, store the directory path that was selected and use it the next time you display the dialog.