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. How to add GUI to a Qt console application?
Forum Updated to NodeBB v4.3 + New Features

How to add GUI to a Qt console application?

Scheduled Pinned Locked Moved Solved General and Desktop
pro fileconsolegui
3 Posts 2 Posters 8.1k 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.
  • ZoltanZ Offline
    ZoltanZ Offline
    Zoltan
    wrote on last edited by
    #1

    I created a Non-Qt project with the qmake build system. I created another project, but this time a Qt Widgets Application. They both work individually, but I now want to have only one project: i.e. add the GUI project to the console project. How should I modify the .pro file of the console application to achieve it?

    This is my console project:

    TEMPLATE = app
    CONFIG += console
    CONFIG -= app_bundle
    CONFIG -= qt
    
    SOURCES += src/gregorian.c \
        src/main.c
    
    

    And this is my GUI project:

    #-------------------------------------------------
    #
    # Project created by QtCreator 2016-08-21T16:32:41
    #
    #-------------------------------------------------
    
    QT       += core gui
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = ZellerGUI
    TEMPLATE = app
    
    
    SOURCES += main.cpp\
            zellergui.cpp \
        gregorian.cpp
    
    HEADERS  += zellergui.h \
        gregorian.h
    
    FORMS    += zellergui.ui
    

    By the way, if I know in advance that I might have a GUI, is it recommended to create a Qt Widgets Application from the start? If it happens to remain without GUI, can it be later modified to a console application?

    Thank you.

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

      Hi,

      You have an example in the detailed documentation of QApplication on how to start an application either as console or GUI app.

      The most simple path would be to copy your classes from your console application to your GUI application and then modify the main.cpp to start in on or the other mode and you should be fine.

      Hope it helps

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

      ZoltanZ 1 Reply Last reply
      2
      • SGaistS SGaist

        Hi,

        You have an example in the detailed documentation of QApplication on how to start an application either as console or GUI app.

        The most simple path would be to copy your classes from your console application to your GUI application and then modify the main.cpp to start in on or the other mode and you should be fine.

        Hope it helps

        ZoltanZ Offline
        ZoltanZ Offline
        Zoltan
        wrote on last edited by
        #3

        @SGaist Thank you, I will try it!

        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