我用谷歌搜索了很多,但找不到任何相关的解决方案来解决我的问题。
问题:我想打开 .MTS
文件,如果它在任何 目录
中可用,则查找它的工作。但是,如果它在任何 package
中,那么我的 QFileDialog
将无法查看该包并选择那些 .MTS
文件。
代码:
auto filePaths = QFileDialog::getOpenFileNames(this, "Open Video File", lastOpenedPath, "*.MTS;*.mov");
qDebug() << "File Paths " << filePaths;
现在索尼和松下高清摄像机在 AVCHD(高级视频编码高清)
包下创建的 .MTS
文件默认,我想导入/选择 .MTS
文件。
提示 QFileDialog
可以在Windows 机器上导入/选择那些.MTS
文件,但在mac 机器上无法导入/选择.
非常感谢任何想法。
谢谢。
最佳答案
好吧,如果我理解您想正确地做些什么,我不确定仅在 Qt 中是否可行。
事实证明,简单地调用 Cocoa 和 NSOpenPanel
确实比我预期的要容易。实现我认为您正在寻找的东西。
示例项目位于:https://github.com/NSGod/widgetsOpenFileDialogCocoa
基本上,我重命名为mainwindow.cpp
至 mainwindow.mm
, 然后添加一个 #import <Cocoa/Cocoa.h>
:
#import <Cocoa/Cocoa.h>
void MainWindow::on_openFileButton_clicked()
{
NSOpenPanel *openPanel = [NSOpenPanel openPanel];
[openPanel setAllowedFileTypes:[NSArray arrayWithObjects:@"mts", @"mov", nil]];
[openPanel setAllowsMultipleSelection:YES];
[openPanel setTreatsFilePackagesAsDirectories:YES];
[openPanel setTitle:@"Open Video File"];
NSInteger result = [openPanel runModal];
QStringList stringList;
if (result == NSFileHandlingPanelOKButton) {
NSArray *URLs = [openPanel URLs];
NSLog(@"URLs == %@", URLs);
for (NSURL *URL in URLs) {
stringList += QString::fromNSString(URL.path);
}
// do something with stringList
qDebug() << "filePaths == " << stringList;
}
}
项目中包含一个 fakeBundle.component
目录,OS X 会将其视为一个包(或“包”)。但是通过设置 treatsFilePackagesAsDirectories
是,你可以拥有 NSOpenPanel
将其视为一个目录(当然,它确实是一个目录)。
这是一张图片,显示了 Finder 如何处理这个 fakeBundle.component
目录就像一个文件一样:
在 NSOpenPanel
中,它被视为一个目录:
关于c++ - QFileDialog:如何在 osX 中从包中打开/选择文件/目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36595747/