如何将a转换CFURLRef为C++ std::string?
我还可以从转换CFURLRef的CFStringRef方式:
CFStringRef CFURLGetString ( CFURLRef anURL );
Run Code Online (Sandbox Code Playgroud)
但现在我有同样的问题.我怎样才能转换CFStringRef为std::string?
我在解析mac上的别名链接时遇到问题.我正在检查文件是否是别名然后我想要接收原始路径.相反,我只获得了一个文件ID.想法?
func isFinderAlias(path:String) -> Bool? {
var isAlias:Bool? = false // Initialize result var.
// Create a CFURL instance for the given filesystem path.
// This should never fail, because the existence isn't verified at this point.
// Note: No need to call CFRelease(fUrl) later, because Swift auto-memory-manages CoreFoundation objects.
print("path before \(path)");
let fUrl = CFURLCreateWithFileSystemPath(nil, path, CFURLPathStyle.CFURLPOSIXPathStyle, false)
print("path furl \(fUrl)");
// Allocate void pointer - no need for initialization,
// it will be assigned to by CFURLCopyResourcePropertyForKey() …Run Code Online (Sandbox Code Playgroud) 尝试使用Qt访问Mac .app包中的resources文件夹的文件路径.这是我的代码:
CFURLRef appUrlRef;
appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR("AFE-MP-512"),NULL,NULL);
CFStringRef filePathRef = CFURLCopyPath(appUrlRef);
qDebug() << filePathRef;
// Release references
CFRelease(filePathRef);
CFRelease(appUrlRef);
Run Code Online (Sandbox Code Playgroud)
我唯一拥有的是表单上的按钮来运行代码.尝试编译时出现以下错误:
Undefined symbols for architecture x86_64:
"_CFBundleCopyResourceURL", referenced from:
MainWindow::on_pushButton_clicked() in mainwindow.o
"_CFBundleGetMainBundle", referenced from:
MainWindow::on_pushButton_clicked() in mainwindow.o
"_CFRelease", referenced from:
MainWindow::on_pushButton_clicked() in mainwindow.o
"_CFURLCopyPath", referenced from:
MainWindow::on_pushButton_clicked() in mainwindow.o
"___CFConstantStringClassReference", referenced from:
CFString in mainwindow.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [ProgramLaunch.app/Contents/MacOS/ProgramLaunch] …Run Code Online (Sandbox Code Playgroud)