Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [solved] no console window opened from empty project template
Forum Updated to NodeBB v4.3 + New Features

[solved] no console window opened from empty project template

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 2.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    T3STY
    wrote on 4 Jan 2014, 03:42 last edited by
    #1

    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>
    #endif

    int main(int argc, char *argv[]){
    #ifdef GUI // GUI
    QApplication app(argc, argv);
    QWidget mywindow;
    mywindow.show();
    #else // CONSOLE
    QCoreApplication app(argc, argv);
    #endif

    return 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?

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on 4 Jan 2014, 06:53 last edited by
      #2

      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.

      1 Reply Last reply
      0
      • T Offline
        T Offline
        T3STY
        wrote on 4 Jan 2014, 07:58 last edited by
        #3

        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.

        1 Reply Last reply
        0
        • T Offline
          T Offline
          T3STY
          wrote on 19 Jan 2014, 12:31 last edited by
          #4

          Updating: I found the right checkbox, it is in the run tab of the project. It's working fine now ;)

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved