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. CMake shows console
Qt 6.11 is out! See what's new in the release blog

CMake shows console

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.7k 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.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by lincoln
    #1

    Hi guys, I have a question about CMake, I made an app and when I run in QtCreator everything goes well, my question is when I generate the release, a cosnola is shown along with my app, why does this happen, and how can I avoid it.

    Here my code:

    #include "mainwindow.h"
    #include "./ui_mainwindow.h"
    #include <QMessageBox>
    #include <QSqlDatabase>
    #include <QSqlError>
    #include <QSqlTableModel>
    
    
    MainWindow::MainWindow(QWidget *parent)
      : QMainWindow(parent), ui(new Ui::MainWindow)
    {
      ui->setupUi(this);
      QSqlDatabase db=QSqlDatabase::addDatabase("QPSQL");
      if(!db.isDriverAvailable("QPSQL")){
          QMessageBox::critical(this,qApp->applicationName(),db.lastError().text());
          return;
        }
      db.setDatabaseName("covid");
      db.setHostName("localhost");
      db.setPassword("12345678");
      db.setPort(5432);
      db.setUserName("postgres");
      if(!db.open()){
          QMessageBox::critical(this,qApp->applicationName(),db.lastError().text());
          return;
        }
      QMessageBox::information(this,qApp->applicationName(),"Todo bien");
    }
    
    MainWindow::~MainWindow()
    {
      delete ui;
    }
    
    **CMakeLists.text:**
    
    cmake_minimum_required(VERSION 3.5)
    
    project(untitled1 LANGUAGES CXX)
    
    set(CMAKE_INCLUDE_CURRENT_DIR ON)
    
    set(CMAKE_AUTOUIC ON)
    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTORCC ON)
    
    set(CMAKE_CXX_STANDARD 11)
    set(CMAKE_CXX_STANDARD_REQUIRED ON)
    
    # QtCreator supports the following variables for Android, which are identical to qmake Android variables.
    # Check http://doc.qt.io/qt-5/deployment-android.html for more information.
    # They need to be set before the find_package(Qt5 ...) call.
    
    #if(ANDROID)
    #    set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
    #    if (ANDROID_ABI STREQUAL "armeabi-v7a")
    #        set(ANDROID_EXTRA_LIBS
    #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
    #            ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
    #    endif()
    #endif()
    
    find_package(QT NAMES Qt6 Qt5 COMPONENTS Widgets REQUIRED)
    find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Widgets REQUIRED)
    find_package(Qt5 COMPONENTS Sql REQUIRED)
    
    if(ANDROID)
      add_library(untitled1 SHARED
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
      )
    else()
      add_executable(untitled1
        main.cpp
        mainwindow.cpp
        mainwindow.h
        mainwindow.ui
      )
    endif()
    
    target_link_libraries(untitled1 PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)
    target_link_libraries(untitled1 PUBLIC Qt${QT_VERSION_MAJOR}::Sql)
    
    

    here I show the windows that are shown every time I run the .exe

    bf5e810f-88cf-439c-8b3e-3f2a827e95bc-image.png

    Solitary wolf

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      For Windows you can add something like:

      set_property(TARGET main PROPERTY WIN32_EXECUTABLE true)
      

      There are other possibilities like set_target_properties, I'll let you decide what best fits your needs.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • lincolnL Offline
        lincolnL Offline
        lincoln
        wrote on last edited by
        #3

        great, I was able to fix my problem now, thanks.

        Solitary wolf

        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