0

尝试在 OSX 10.6.8、Qt 4.7 下使用 QFileDialog:

QFileDialog *dialog = new QFileDialog(0,tr("Load Band Recordings"),qbh,tr("Wave Files (*.wav)"));
dialog->setFileMode(QFileDialog::ExistingFiles);

if (dialog->exec())
{
QStringList fileNames;
    fileNames = dialog->selectedFiles();
    qs = fileNames[0];
}
else
{
    return(0);
}

它可以工作,但许多错误被转储到控制台:

Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: Failed to create window context device
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGWindowContextCreate: failed to create context delegate.
2012-05-13 11:03:41.445 SdrDx[18982:903] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x31197, window:0xffffffff
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextSaveGState: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextTranslateCTM: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextScaleCTM: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextAddRect: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: doClip: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextRestoreGState: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: Failed to create window context device
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGWindowContextCreate: failed to create context delegate.
2012-05-13 11:03:41.533 SdrDx[18982:903] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x31197, window:0xffffffff
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextSaveGState: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextTranslateCTM: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextScaleCTM: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextAddRect: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: doClip: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextRestoreGState: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: Failed to create window context device
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGWindowContextCreate: failed to create context delegate.
2012-05-13 11:03:41.576 SdrDx[18982:903] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x31197, window:0xffffffff
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextSaveGState: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextTranslateCTM: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextScaleCTM: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: CGContextAddRect: invalid context 0x0
Sun May 13 11:03:41 machine-mac-pro.local SdrDx[18982] <Error>: doClip: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextRestoreGState: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: Failed to create window context device
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGWindowContextCreate: failed to create context delegate.
2012-05-13 11:03:41.616 SdrDx[18982:903] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x31197, window:0xffffffff
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextSaveGState: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextTranslateCTM: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextScaleCTM: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextAddRect: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: doClip: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextRestoreGState: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: Failed to create window context device
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGWindowContextCreate: failed to create context delegate.
2012-05-13 11:03:41.638 SdrDx[18982:903] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x31197, window:0xffffffff
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextSaveGState: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextTranslateCTM: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextScaleCTM: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextAddRect: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: doClip: invalid context 0x0
Sun May 13 11:03:41 -mac-pro.local SdrDx[18982] <Error>: CGContextRestoreGState: invalid context 0x0

文档说提供父小部件;似乎没关系。

任何人都知道如何在 OSX 下正确使用 Qt 4.7 QFileDialog 类,以便它不会向控制台吐出错误?

顺便说一句,文件和目录对话框的静态版本和构造版本都执行此操作。我在 Qt 论坛上询问过,但没有收到任何答复。希望这里有人已经弄清楚了。

4

0 回答 0