[Qt-interest] Qt app launched from CLI or GUI? Can I know in code?
Kishore Jonnalagadda
kitts.mailinglists at gmail.com
Sat Sep 17 10:11:07 CEST 2011
On Sep 16, 2011 4:16 PM, "Rui Maciel" <rui.maciel at gmail.com> wrote:
>
> Kishore Jonnalagadda wrote:
>
> > On Tuesday 26 Jul 2011 11:02:32 PM you wrote:
> >> Basically, in my application, I would like to install a message handler
> >> for debug messages so that they are logged to a file. However, I would
> >> like to do so only if the app were launched from the GUI. So in case
the
> >> app was launched from the CLI, it should output to the terminal as
usual.
> >>
> >> Is this possible? Particularly on a linux machine
> >
> > To answer my own question, i now use isatty() to check this.
> >
> > /****/
> > if(!isatty(fileno(stderr)))
> > qInstallMsgHandler(myMessageOutput);
> > /****/
> >
> > The above code installs a custom message handler if stderr is not a
> > terminal.
>
> Wouldn't it be simpler to set the custom message handler through a flag
> passed through a command line argument? With this, you would only need to
> guarantee that you passed that flag when you executed your app through a
> GUI, and you would gain a flexible way to test your code.
Simpler? Maybe not. The above code is quite simple. But I think the choice
should be driven by the use case for the app. In my case, this was for a
simple utility app where a user would just download the exe and run it. Not
install it. So no menu entries or a .desktop file setting the -gui option.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20110917/0a21b143/attachment.html
More information about the Qt-interest-old
mailing list