Obj-C 实现 QFileDialog函数(getOpenFileName/getOpenFileNames/getExistingDirectory/getSaveFileName)
1.getOpenFileName
/************************************************************************** @QFileDialog::getOpenFileName @param pChDefFilePath:[input]Default file path @param pChFormat:[input]Save file format @param pChOpenFile:[output]Get the open file path @return: true, success; **************************************************************************/ bool MacGetOpenFileName(const char *pChDefFilePath, const char *pChFormat, char *pChOpenFile) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; bool bRet = false; NSOpenPanel *nsPanel = [NSOpenPanel openPanel]; [nsPanel setCanChooseFiles:YES]; [nsPanel setCanChooseDirectories:NO]; [nsPanel setAllowsMultipleSelection:NO]; NSString *nsDefFilePath = [[NSString alloc] initWithUTF8String: pChDefFilePath]; [nsPanel setDirectory:nsDefFilePath]; NSString *nsFormat = [[NSString alloc] initWithUTF8String: pChFormat]; if (0 != [nsFormat length]) { NSArray *nsFormatArray = [nsFormat componentsSeparatedByString:@","]; [nsPanel setAllowedFileTypes:nsFormatArray]; } memset(pChOpenFile, 0, 256); NSInteger nsResult = [nsPanel runModal]; if (nsResult!=NSFileHandlingPanelOKButton && nsResult!=NSFileHandlingPanelCancelButton) { //QTBUG:recall runModal when QMenu action triggered; [nsDefFilePath release]; nsDefFilePath = nil; [nsFormat release]; nsFormat = nil; [pool drain]; return MacGetOpenFileName(pChDefFilePath, pChFormat, pChOpenFile); } if (nsResult == NSFileHandlingPanelOKButton) { NSString *nsOpenFile = [[nsPanel URL] path]; const char *pChOpenFilePath = [nsOpenFile UTF8String]; while ((*pChOpenFile++ = *pChOpenFilePath++) != '