[Development] Cake and eating it too for qDebug printing to system log - https://codereview.qt-project.org/89357
Thiago Macieira
thiago.macieira at intel.com
Thu Jul 10 20:03:03 CEST 2014
On Thursday 10 July 2014 19:34:59 Oswald Buddenhagen wrote:
> On Thu, Jul 10, 2014 at 10:17:52AM -0700, Thiago Macieira wrote:
> > On Thursday 10 July 2014 16:50:22 Shawn Rutledge wrote:
> > > On Windows I never liked CONFIG += console, because it's never in the
> > > .pro by default (usually not in manual tests or examples, and not in
> > > Creator-generated pro files either) and yet I would like to always
> > > have qDebug output in the console when the app is running in a
> > > console. So detecting whether the app is running in a console and
> > > automatically sending debug output there would mean that we no longer
> > > need that flag in the .pro, right? If it's technically possible, we
> > > should have done that years ago.
> >
> > I don't think it's possible at all. If the application was compiled to the
> > GUI subsystem, it *has* no stdout and stderr. We can open a new console
> > window, but I don't think you can write to an existing one.
>
> "windows is stupid, but it can't be that stupid, can it?" => google =>
>
> AttachConsole(ATTACH_PARENT_PROCESS)
> GetStdHandle(STD_ERROR_HANDLE)
> (and _open_osfhandle(h) if one cares for stdio)
That means we can replace the GetConsoleWindow() call with
AttachConsole(ATTACH_PARENT_PROCESS). If it succeeds or if it returns
ERROR_ACCESS_DENIED, we have a console.
For the Windows folks around: should we do this?
--
Thiago Macieira - thiago.macieira (AT) intel.com
Software Architect - Intel Open Source Technology Center
More information about the Development
mailing list