CMake shows console
Solved
General and Desktop
-
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
-
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.