Results 1 to 6 of 6

Thread: console always popup in release mode

  1. #1

    Default console always popup in release mode

    HI all,

    I had an application which can be launch in GUI mode and in Console Mode :

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "flashloader.h"
    3.  
    4.  
    5. #include "QMap"
    6. #include <iostream>
    7. #include "QMessageBox"
    8.  
    9. int main(int argc, char *argv[])
    10. {
    11. QApplication a(argc, argv);
    12.  
    13. QMessageBox msgBox;
    14. msgBox.setText("number of argument : " + QString::number(argc));
    15. msgBox.exec();
    16.  
    17. QStringList List_args = QApplication::arguments();
    18.  
    19. int iCount;
    20. iCount = argc;
    21. QMap<QString, QString> map_args;
    22.  
    23. FlashLoader w;
    24.  
    25. if (argc == 1)
    26. {
    27. w.show();
    28. return a.exec();
    29. }
    30. else
    31. {
    32. int i;
    33. for (i=1; i < argc ; i++)
    34. {
    35. std::cout << "MainAppCore argv[" << i << "] : " << List_args.at(i).toStdString() << "\n";
    36. }
    37. return 0;
    38. }
    39. }
    To copy to clipboard, switch view to plain text mode 

    In my pro files, I have
    Qt Code:
    1. CONFIG += console
    To copy to clipboard, switch view to plain text mode 
    (necessary to have console working)

    In debug mode all is working well. If I launch the application with no argument I have only the GUI present. If I launch the application with argument I have only the console present. The problem is when I launch the application in release mode ,the console always appears. How can I fix that?

    Thanks

  2. #2
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: console always popup in release mode

    Hi,

    I think that argc will be 1 if there are no arguments because the application name is inserted as the first argument, so you have to check if argc is bigger than 1.
    Òscar Llarch i Galán

  3. #3

    Default Re: console always popup in release mode

    Hi,

    I believe the problems was there. This is why I display a MessageBox. But even in Debug or in Release argc==1 (and I display it in message box).

    This code is running well if I launch from QTCreator in debug and Release mode.

    But I launch it directly from the exe I have always the console present

    Any other Idea?

  4. #4
    Join Date
    Mar 2008
    Location
    Kraków, Poland
    Posts
    1,540
    Thanked 284 Times in 279 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: console always popup in release mode

    Because QTCreator put some args to application ? Line 25 detects if You have some args (argc > 1) or not. If You want to run application with exactly one argument line 25 should be :
    Qt Code:
    1. if(argc == 2)
    To copy to clipboard, switch view to plain text mode 
    BTW it is better use of QCoreApplication::arguments.

  5. #5

    Default Re: console always popup in release mode

    Ok please don't focus on number of arg !!!
    If I use this code :
    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. FlashLoader w;
    6.  
    7. w.show();
    8. return a.exec();
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 
    and in my pro file
    Qt Code:
    1. CONFIG += console
    To copy to clipboard, switch view to plain text mode 

    If I run in Debug or Release mode through QTcreator I have no console open

    If I run directly the exe, I have always console present

  6. #6
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: console always popup in release mode

    Hi,

    You can use "--console" as argument to your application. In "main.cpp" you have to search if there is "--console" in some of the arguments. If you find it you can open your application as console and if you don't find it open as GUI.
    Òscar Llarch i Galán

Similar Threads

  1. Replies: 1
    Last Post: 7th March 2012, 21:34
  2. Replies: 11
    Last Post: 19th August 2010, 13:14
  3. Replies: 1
    Last Post: 2nd November 2009, 12:02
  4. Replies: 9
    Last Post: 15th April 2009, 06:23
  5. Replies: 8
    Last Post: 10th October 2007, 18:20

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.