Qt QFileDialog -- proper use under OSX
-
QT 4.7, OSX 10.6.8
hi. I'm using QFileDialog, and it's working in the UI sense, but on the OSX error console, I am seeing a large number of messages from OSX complaining about not having a top level window and so forth.
QFileDialog is documented as requiring a "parent widget" to be passed to it. I've tried regular widgets, widgets that contain other widgets, the window... same console result. Clearly OSx is very unhappy, and odds are -- I hope -- that I'm doing this entirely wrong and the only reason its working is some kind of beneficent fallback mode for OSX.
So, I've got a UI made with Qt designer. What should I pass QFileDialog in order that it work as designed? Here's my call; at the moment, "parent" is a QWidget, last try, it was "this", which would be the mainwindow object, I believe, or possibly the play QWidget that leads to opening this file, either way, same result, I've also tried it with a cached pointer to the window widget:
@
qbh = QDir::homePath();
qbh += "/sdr_recordings";
QFileDialog dialog = new QFileDialog(parent,
tr("Load Band Recordings"),
qbh,
tr("Wave Files (.wav)"));
@Here are some of the first emitted osx console errors (there are many more):
@
4/16/12 10:54:36 PM [0x0-0x1154153].com.yourcompany.SdrDx[11118] Mon Apr 16 22:54:36 mac-pro.local SdrDx[11118] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
4/16/12 10:54:36 PM [0x0-0x1154153].com.yourcompany.SdrDx[11118] Mon Apr 16 22:54:36 mac-pro.local SdrDx[11118] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
4/16/12 10:54:36 PM [0x0-0x1154153].com.yourcompany.SdrDx[11118] Mon Apr 16 22:54:36 mac-pro.local SdrDx[11118] <Error>: Failed to create window context device
4/16/12 10:54:36 PM SdrDx[11118] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x2aabf, window:0xffffffff
4/16/12 10:54:36 PM [0x0-0x1154153].com.yourcompany.SdrDx[11118] Mon Apr 16 22:54:36 mac-pro.local SdrDx[11118] <Error>: CGWindowContextCreate: failed to create context delegate.
4/16/12 10:54:36 PM [0x0-0x1154153].com.yourcompany.SdrDx[11118] Mon Apr 16 22:54:36 mac-pro.local SdrDx[11118] <Error>: CGContextSaveGState: invalid context 0x0
4/16/12 10:54:36 PM [0x0-0x1154153].com.yourcompany.SdrDx[11118] Mon Apr 16 22:54:36 mac-pro.local SdrDx[11118] <Error>: CGContextTranslateCTM: invalid context 0x0
4/16/12 10:54:36 PM [0x0-0x1154153].com.yourcompany.SdrDx[11118] Mon Apr 16 22:54:36 mac-pro.local SdrDx[11118] <Error>: CGContextScaleCTM: invalid context 0x0@Thank you!
-
wow, 52 views and not one reply?
Are the file dialogs just plain broken, or is it that no one actually knows how to use them?
-
They work for me, but I usually use the "static convenience methods":/doc/qt-4.8/QFileDialog.html#static-public-members.
-
I'm not at all certain they actually work for you, in the sense that they don't produce vomit on the console. have you tried opening one of these with the system console app running? If you have, and there's no vomit, then are you using qt 4.7? Is there any precursor step you do?
Because this call from your list of static methods...
@
qs = QFileDialog::getExistingDirectory(tmw,"Select Recording Directory",g_fileTarget,QFileDialog::ShowDirsOnly);
@...produces this for me:
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: kCGErrorFailure: Set a breakpoint @ CGErrorBreakpoint() to catch errors as they are logged.
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: Failed to create window context device
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGWindowContextCreate: failed to create context delegate.
2012-05-02 17:23:39.116 SdrDx[50123:903] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x26cf7, window:0xffffffff
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextSaveGState: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextTranslateCTM: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextScaleCTM: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextAddRect: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: doClip: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextRestoreGState: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: Failed to create window context device
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGWindowContextCreate: failed to create context delegate.
2012-05-02 17:23:39.211 SdrDx[50123:903] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x26cf7, window:0xffffffff
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextSaveGState: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextTranslateCTM: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextScaleCTM: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextAddRect: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: doClip: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextRestoreGState: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: kCGErrorIllegalArgument: _CGSFindSharedWindow: WID -1
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: kCGErrorIllegalArgument: CGSDeviceCreate: Invalid window
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: Failed to create window context device
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGWindowContextCreate: failed to create context delegate.
2012-05-02 17:23:39.236 SdrDx[50123:903] _initWithWindowNumber: error creating graphics ctxt object for ctxt:0x26cf7, window:0xffffffff
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextSaveGState: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextTranslateCTM: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextScaleCTM: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextAddRect: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: doClip: invalid context 0x0
Wed May 2 17:23:39 eight-cores-mac-pro.local SdrDx[50123] <Error>: CGContextRestoreGState: invalid context 0x0 -
Still nothing? I guess the assumption is that Qt 4.7 is badly broken, then?
-
ho-hum, still no one. Is it that we completely lack anyone from Qt itself who knows how things actually work, or is it that they simply don't care?
-
It may be that there are errors on the console here too, I didn't check and if there were any, I'd ignore them, as my programs "just work".
-
I don't call a program that is spewing OS errors "working." Not just because the OS is obviously being used in a way it doesn't consider kosher, but also because the console is used by others as a means to determine proper operation of any number of other applications, and dumping lots of error messages out on it makes it considerably more difficult to use the console as intended.
I take the same approach with coding: If the compiler is producing warnings, the code isn't correct. And for the same reason. If the compiler is dumping many more-or-less "safe" warnings, it makes it a lot more difficult to see the ones I need to see, and that is uniformly a bad thing.
Bottom line here, either Qt is broken, or I'm using the dialog wrong. And since I'm using it the way they say to use it, I'm inclined towards Qt is broken. Further, given my experience thus far with the monumentally-busted QAudioInput and a few other things, I've begun to look for Qt problems fairly early in the debugging process.
-
I didn't check every one of your errors, but many of them seem to be related with new features introduced in Lion (Versions, Mission Control, etc.). Qt 4.7 does not officially support Lion, so I guess you'll have to live with some glitches, even if they generate (non-critical) OS errors.
-
No, sorry. I don't use Lion -- it has broken multi-monitor support, and as I have six monitors, I've no interest in it. Also sandboxing, certificating, etc. Lion is a regression as far as I'm concerned.
I use Snow Leopard and Leopard in-house, and the errors I described here were discovered and exist under those: 10.5. and 10.6. Those are 10.6 (Snow Leopard) diagnostics in my post above.
What you've managed to do, however, is confirm that the Qt bug is problematic under Lion / 10.7 as well, for which I thank you. :)