[solved] no console window opened from empty project template
-
after my last thread about configuring a project for both console and gui application in a single .pro file (link http://qt-project.org/forums/viewthread/36757 ) I tried at least to achieve the objective of compiling the same application as console or gui manually, by only using the necessary qmake configuration lines.
I started with an empty project template from the QtCreator New project wizard. I then added a simple main.cpp file made like this:
@
#define CONSOLE // define either CONSOLE or GUI#ifdef GUI // GUI
#include <QApplication>
#include <QWidget>
#else // CONSOLE
#include <QCoreApplication>
#endifint main(int argc, char *argv[]){
#ifdef GUI // GUI
QApplication app(argc, argv);
QWidget mywindow;
mywindow.show();
#else // CONSOLE
QCoreApplication app(argc, argv);
#endifreturn app.exec();
}
@Then, when I built the project for a console app I defined CONSOLE in main.cpp (at line 1), and I used this project configuration:
@
QT += core
QT -= gui
CONFIG += console
SOURCES += main.cpp
@When I built the project for a gui app instead I defined GUI in main.cpp (at line 1), and I used this project configuration:
@
QT += gui core widgets
CONFIG -= console
SOURCES += main.cpp
@As expected when experimenting, in theory anything works; in practice, you don't get the expected result. In both cases the project compilation goes fine, but the console application won't show a console window; instead the gui application correctly opens the mywindow widget window.
When I create a console project from the project wizard I noticed it doesn't even matter if CONFIG += console is defined or not in the .pro file. Even if I only leave a SOURCES += main.cpp line (deleting anything else in the .pro file) the application will still open a console window, and instead it would open both a console and a gui widget if QT += gui core widgets is specified (using the same main.cpp file above).
I tried in many many ways to get a console window or a gui window based on the .pro configuration, but I've been unsuccessful all the times. No matter how I configure the .pro file, the base template that I choose in the project wizard will make the application go console or gui, and my configuration in the .pro file will totally be ignored about this.
Can someone tell me what am I doing wrong ? Or am I missing anything on how QtCreator treats .pro files or projects in general?
-
Please note that, there is a "Run in terminal" option in your project settings page provided by Qt Creator. Which has nothing to do with console or windows.
And note that, "CONFIG += console" only make sense for Windows.
-
I found a "SESSIONNAME" environment variable, if I set it to gui or console it works as set, if instead I simply unset it the project will decide which environment to use based on the project configuration and include files.
Is there any other variable I should take care of? Looks like SESSIONNAME is doing the job and i can't find any other for that purpose. -
Updating: I found the right checkbox, it is in the run tab of the project. It's working fine now ;)