Results 1 to 5 of 5

Thread: How to create single exe for Console & GUI mode

  1. #1
    Join Date
    May 2009
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default How to create single exe for Console & GUI mode

    Hi All,

    How can I create single exe for Console and Gui mode in Qt ???

    Thanks in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to create single exe for Console & GUI mode

    interpreted argv and if the user gives you a console flag, don't call show() on your mainwindow.

  3. #3
    Join Date
    May 2009
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to create single exe for Console & GUI mode

    Hi ,

    Thanks for your reply.
    Can you please elaborate it with small example ,I searched a lot in net, but didn't get much help.

    My requirement is just by setting some flag in config file(which is outside the application) application should be able to change the mode(GUI/Console) dynamically.

    Once again thanks.

    PS: I am using Qt4.3.2.
    Last edited by summer_of_69; 10th June 2009 at 14:07.

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to create single exe for Console & GUI mode

    E.g.:
    Qt Code:
    1. void main(int argc, char *argv[])
    2. {
    3. bool isConsole = false
    4. for(int i=0;i<argc;i++)
    5. if ("console" == argv[i])
    6. isConsole = true;
    7.  
    8. QApplication app(argc, argv);
    9. MainWindow mainWin;
    10. if (!isConsole)
    11. {
    12. mainWin.setupGui();
    13. mainWin.show();
    14. }
    15. return app.exec();
    16. }
    To copy to clipboard, switch view to plain text mode 

    ./myapp console

    Or you can change... Switch from Gui to console application, just hide the mainwindow.

  5. #5
    Join Date
    May 2009
    Posts
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to create single exe for Console & GUI mode

    This will possibly not work and GUI thread will block the Console window, because my program Linker>>system>>subsystem has Windows (/SUBSYSTEM:WINDOWS) value not "Console". I want to do this dynamically with progam.

    I think I am not clear.
    When you create one Qt Core application and try to print any thing using operator Cout or fgets() it sends the output to Console window(command prompt) and you can see the output there, but if you use Qt(GUI) mode you can't see command prompt .This is because GUI thread blocks it .
    I know this can be invoked using QProcess::startdetached("Cmd.exe"),but by using this I need to change the whole code ,I mean I can't simply send/recieve the output to console using cout/fgets() and all this can be done if I use console mode of Qt (Qt-Core).That's the reason I want two mode in my single executable so that user can operate on either mode just by some configuration settings.

    I hope I have explain the problem domain.

    I have gone through various links about this but nothing works for me
    http://stackoverflow.com/questions/4...le-and-gui-app

Similar Threads

  1. Multiple project files in a single directory
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 17th July 2008, 07:03
  2. How to create filmstrip - multiple images in a single file
    By jessiemmichael in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 08:30
  3. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.