C++ (Qt)QString name = QFileDialog::getSaveFileName(0, "Create Project File", "/Users/igor/Documents/Gro3.prj");
QFileDialog *dlg = new QFileDialog(); dlg->setWindowTitle("Create Project File"); dlg->selectFile("/Users/igor/Documents/Gro3.prj"); int res = dlg->exec(); if(res == QFileDialog::Accepted) { QString name = dlg->selectedFiles().at(0); }
C++ (Qt) connect(b, &QPushButton::clicked, [this]{ macosHack(); QString name = QFileDialog::getSaveFileName(0, "Create Project File", "/Gro3.prj"); }); // в .mm файле#include <dispatch/dispatch.h>#import <AppKit/AppKit.h> void Widget::macosHack(){ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 0.5 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ auto savePanel = static_cast<NSSavePanel *>(NSApp.keyWindow); });}
Objective-C/*BOOL*/ bool isSavePanel = [NSApp.keyWindow isKindOfClass:[NSSavePanel class]];
C++ (Qt)QString CocoaFileSave( const QString & iPrompt, const QString & thePath ){ NSSavePanel * savePanel = [NSSavePanel savePanel]; QFileInfo info(thePath); [savePanel setDirectoryURL: [NSURL fileURLWithPath:info.absolutePath().toNSString()]]; [savePanel setNameFieldStringValue:info.fileName().toNSString()]; [savePanel setAllowsOtherFileTypes:YES]; [savePanel setExtensionHidden:NO]; [savePanel setCanCreateDirectories:YES]; [savePanel setNameFieldLabel:iPrompt.toNSString()]; [savePanel setShowsTagField:NO]; [savePanel setAccessoryView:nil]; // Call processEvents in case the event dispatcher has been interrupted, and needs to do // cleanup of modal sessions. Do this before showing the native dialog, otherwise it will // close down during the cleanup. qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers); // Make sure we don't interrupt the runModal call below. clearCurrentThreadCocoaEventDispatcherInterruptFlag(); auto result = [savePanel runModal]; QAbstractEventDispatcher::instance()->interrupt(); if (result != NSModalResponseOK) return QString(); return QString::fromNSString([[savePanel URL] path]).normalized(QString::NormalizationForm_C);}
Objective-C@autoreleasepool {// код}
Objective-Cauto pool = [NSAutoreleasePool new];// код[pool release];return some_cpp_object;
QMacAutoReleasePool pool; // добавить первой строкой