Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9083619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:49:01+00:00 2026-06-16T20:49:01+00:00

I am using the combination mentioned in the title while trying to run the

  • 0

I am using the combination mentioned in the title while trying to run the window layout example from the qt tutorials. The main looks like this:

#include <QtGui>

int main(int argc, char **argv) {
  QApplication app(argc, argv);
  QWidget window;
  QLabel *label = new QLabel(QApplication::translate("windowlayout", "Name:"));
  QLineEdit *lineEdit = new QLineEdit();

  QHBoxLayout *layout = new QHBoxLayout();
  layout->addWidget(label);
  layout->addWidget(lineEdit);
  window.setLayout(layout);
  window.setWindowTitle(
      QApplication::translate("windowlayout", "Window layout"));
  window.show();
  return app.exec();
}

And the CMakeLists.txt like this:

PROJECT(test)
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)

FIND_PACKAGE(Qt4 REQUIRED)
INCLUDE_DIRECTORIES(${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR} ${QT_QTGUI_INCLUDE_DIR})

SET(test_SRCS main.cc)

QT4_AUTOMOC(${test_SRCS})

ADD_EXECUTABLE(test ${test_SRCS})

TARGET_LINK_LIBRARIES(test ${QT_QTGUI_LIBRARIES} ${QT_QTCORE_LIBRARIES})

The building and compilation work properly but when I run the application, it always show a command prompt. How do I avoid that?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T20:49:02+00:00Added an answer on June 16, 2026 at 8:49 pm

    In your CMakeFile with Qt4, you don’t need to change your CPP code or to add flags at compile time. Simply use

    set(QT_USE_QTMAIN TRUE)
    

    It will automatically link qtmain.lib with your executable. This library defines other common main() signatures, including WinMain().

    With this trick, your app can compile with MSVC under Windows, without mofiying your original main() function and without displaying a console when you run your app outside of your IDE (QtCreator for example).

    Final resulting CMakeLists.txt can be :

    PROJECT(test)
    CMAKE_MINIMUM_REQUIRED(VERSION 2.8.0)
    
    FIND_PACKAGE(Qt4 REQUIRED)
    if(WIN32)
        SET(QT_USE_QTMAIN TRUE)
    endif(WIN32)
    
    INCLUDE(${QT_USE_FILE})
    
    SET(test_SRCS main.cc)
    
    QT4_AUTOMOC(${test_SRCS})
    
    ADD_EXECUTABLE(test ${test_SRCS})
    
    TARGET_LINK_LIBRARIES(test ${QT_LIBRARIES})
    

    Additionnaly, you don’t need to include QtCore and QtGui, they are included by default with QT_USE_FILE (for include folders) and QT_LIBRARIES (for libraries).

    You only have to set what modules you use, or you don’t use (for Gui) :

    # Use Network and Sql modules
    set(QT_USE_QTNETWORK TRUE)
    set(QT_USE_QTSQL TRUE)
    # Do not use Gui module
    set(QT_DONT_USE_QTGUI TRUE)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to make a layout using Java Swing which looks like the
Classification and regression trees by Breiman et al mentioned about using linear combination of
I'm using the combination of json_encode (PHP) and JSON.parser (Javascript from json.org) for passing
I am trying to make a search function using the combination of DOM, PHP
I am using combination of PyQt and beautiful soup to scrape data from a
Using Rails 3.0.3 in combination with gems like devise I don't get any flash
I am thinking about using on of the technologies mentioned in the title but
I'm trying to create a WYSIWYG editor using a div, just like Google Docs
Can anyone suggest me a solution for the above mentioned combination. I'm using Eclispe
I'm using a combination of Knockout.js + the Knockout mapping plugin + jQuery in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.