Results 1 to 5 of 5

Thread: Switching between console and GUI on startup

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2007
    Location
    Quebec, Canada
    Posts
    40
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    4

    Default Switching between console and GUI on startup

    I'm trying to add console support to my already working application. So I get in the main to add some switch support to the command line but it is not poping any command line when entering the right switch. Here's a little main In crafted to try this coexistence :

    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. // for cout
    5. #include <iostream>
    6. using namespace std;
    7.  
    8. int main( int argc, char** argv )
    9. {
    10. bool console = false;
    11. if ( argc > 1 )
    12. {
    13. // Check if user selected console mode.
    14. for ( int i=1; i<argc; ++i )
    15. {
    16. if ( !strcmp( argv[i], "-console" ) )
    17. {
    18. console = true;
    19. break;
    20. }
    21. }
    22. }
    23.  
    24. if ( console )
    25. {
    26. QCoreApplication app( argc, argv );
    27.  
    28. // This is not working.
    29. cout << "Console Mode" << endl;
    30.  
    31. // Try to write a file.
    32. QFile myFile( "C:\\Temp\\Test.txt" );
    33. myFile.open( QIODevice::WriteOnly | QIODevice::Text );
    34.  
    35. QDataStream stream( &myFile );
    36. stream << "Console is working but not showing";
    37.  
    38. return 0;
    39. }
    40. else
    41. {
    42. QApplication app(argc, argv);
    43.  
    44. QLabel* label = new QLabel( "GUI !!!" );
    45. label->show();
    46.  
    47. return app.exec();
    48. }
    49. }
    To copy to clipboard, switch view to plain text mode 

    The file gets written but I don't get any output to the console. I added the switch to tell it is a command line app and I can see the output however, I will get a console even if I'm in GUI mode.

    How can I achieve an application that can be executed in either mode ?

    Another question, does my -console switch is already used by Qt ?
    Attached Files Attached Files

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.