Results 1 to 2 of 2

Thread: Redirecting stdout to a console in Qt

  1. #1
    Join Date
    Dec 2011
    Posts
    4
    Qt products
    PyQt3 PyQt4

    Default Redirecting stdout to a console in Qt

    Hi,

    I've read mulitple threads related to what I'm looking for, but none answered the questions that I have.

    Basically what I want to do is the following,

    I have a Qt application that is a GUI. This application will sometimes instead of being executed with a double click (.exe), will be run from the command line with some variables.
    Now, if it's run from command line and (argc > 1), then I would like to print messages to this console (Note: not in another window).

    Now I noticed that if I don't put CONFIG += console in my .pro, then all my qDebug or printf messages do not get printed. I do not want to run my application as a console application
    because when I double click I will get an unwated console window which is not what I want.

    I also do not like the way another thread had found the solution where I have to projects, one .com and one .exe and in main according to the no. of arguments decide which one to run.
    Another solution that I did not like is attaching a console to the app if arguments is present, because then when I run the app from command line, I get another window that pops up.

    Basically what I want to know is, if there is a call that I could do to find out if the app was run form a commandline, and if so then get the console's like processor's id or something and then
    redirect all my print messages to that console window (where the application was run from).

    thanks

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    3
    Thanked 127 Times in 126 Posts

    Default Re: Redirecting stdout to a console in Qt

    "Basically what I want to know is, if there is a call that I could do to find out if the app was run form a commandline"

    No, I don't think so.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

Similar Threads

  1. Replies: 26
    Last Post: 23rd April 2011, 11:44
  2. problem while redirecting using qtnetworkreply
    By itskay007 in forum Newbie
    Replies: 0
    Last Post: 19th September 2010, 16:00
  3. redirecting ASSERTs
    By drhex in forum Qt Programming
    Replies: 2
    Last Post: 24th July 2009, 22:59
  4. QT4 HTTP Example and Redirecting
    By jiveaxe in forum Qt Programming
    Replies: 3
    Last Post: 4th June 2008, 17:42
  5. Redirecting qDebug()
    By hardgeus in forum Qt Programming
    Replies: 1
    Last Post: 23rd December 2006, 02:39

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.