PDA

View Full Version : console always popup in release mode



gerardpuducul
8th April 2013, 11:45
HI all,

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


#include <QtGui/QApplication>
#include "flashloader.h"


#include "QMap"
#include <iostream>
#include "QMessageBox"

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

QMessageBox msgBox;
msgBox.setText("number of argument : " + QString::number(argc));
msgBox.exec();

QStringList List_args = QApplication::arguments();

int iCount;
iCount = argc;
QMap<QString, QString> map_args;

FlashLoader w;

if (argc == 1)
{
w.show();
return a.exec();
}
else
{
int i;
for (i=1; i < argc ; i++)
{
std::cout << "MainAppCore argv[" << i << "] : " << List_args.at(i).toStdString() << "\n";
}
return 0;
}
}

In my pro files, I have

CONFIG += console (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

^NyAw^
8th April 2013, 12:56
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.

gerardpuducul
8th April 2013, 15:30
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?

Lesiok
8th April 2013, 16:25
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 :
if(argc == 2)
BTW it is better use of QCoreApplication::arguments.

gerardpuducul
9th April 2013, 15:11
Ok please don't focus on number of arg !!!
If I use this code :

int main(int argc, char *argv[])
{
QApplication a(argc, argv);

FlashLoader w;

w.show();
return a.exec();

}
and in my pro file

CONFIG += console

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

^NyAw^
9th April 2013, 17:15
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.