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. Regarding manual addition in .pro file for widgets
Forum Updated to NodeBB v4.3 + New Features

Regarding manual addition in .pro file for widgets

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 2.4k 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.
  • S Offline
    S Offline
    sinedie
    wrote on last edited by
    #1

    Hello,
    I used a bit of qt3 and qt4 but was trying to use qt5 for the first time. It seems now, as I learned from several websites, it is required to add the following line for many simple GI-based programs.

    QT += widgets

    I was wondering why is this so. I am using QMake version 3.0 and Qt version 5.0.2.

    TIA,
    Sine

    1 Reply Last reply
    0
    • JKSHJ Offline
      JKSHJ Offline
      JKSH
      Moderators
      wrote on last edited by
      #2

      In Qt 4 and Qt 5, QMake automatically adds "QT += core" and "QT += gui" for you.

      In Qt 4, widgets were part of the "GUI" module. But in Qt 5, widgets have been split off into a new "Widgets" module.

      That means, in Qt 5, widgets are no longer automatically added by QMake.

      Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi, welcome to devnet.

        Qt5 was modularized to allow smaller deployments and easier development.

        QtWidgets in particular was separated from general GUI module, so now you don't have to include it for example when you use only QtQuick or pure OpenGL windows.

        A complete list of Qt5 modules is "here":http://qt-project.org/doc/qt-5.0/qtdoc/modules.html

        1 Reply Last reply
        0
        • S Offline
          S Offline
          sinedie
          wrote on last edited by
          #4

          Thanks JKSH and Chris Kawa for the patient replies.

          My point is why does that statement need to be added manuallyif it can be automatically included by qmake. For instance it could be suggested to the users to have a statement such as below that could cause qmake to add the necessary statement in the .pro file.

          @#include <QtWidgets>@

          I am unable to understand the necessity of having to do it explicitly to the project file sacrificing the user friendliness of Qt.

          1 Reply Last reply
          0
          • JKSHJ Offline
            JKSHJ Offline
            JKSH
            Moderators
            wrote on last edited by
            #5

            Because Qt now offers 3 major ways for creating GUIS:

            • Widgets
            • QML
            • Low-level OpenGL

            Not all GUIs use widgets, so not all projects need "QT += widgets".

            In any case, if you tell Qt Creator to create a widget project, Qt Creator DOES add "QT += widgets" for you.

            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

            1 Reply Last reply
            0
            • S Offline
              S Offline
              sinedie
              wrote on last edited by
              #6

              Thanks JKSH. I was writing the code manually so I think I ran into trouble. :)

              1 Reply Last reply
              0
              • JKSHJ Offline
                JKSHJ Offline
                JKSH
                Moderators
                wrote on last edited by
                #7

                You're welcome :)

                [quote author="sinedie" date="1375624145"]...have a statement such as below that could cause qmake to add the necessary statement in the .pro file.

                @#include <QtWidgets>@
                [/quote]I just re-read your suggestion, and think I understand your point better now.

                Actually, it's the other way round: qmake reads "QT += widgets" first, and THEN generates the Makefile that tells your compiler where to find the <QtWidgets> header

                Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  sinedie
                  wrote on last edited by
                  #8

                  I was talking of generating the .pro file as follows:
                  @
                  sh$ qmake -project
                  <manually edit the .pro file generated>
                  sh$ qmake
                  sh$ make
                  @

                  The manual editing could perhaps be avoided. I already see a problem here though, if widgets are not required in the initial pass it could be a mess. Could that be the only reason?

                  1 Reply Last reply
                  0
                  • Chris KawaC Offline
                    Chris KawaC Offline
                    Chris Kawa
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    QT += is basically doing INCLUDEPATH += and a LIBS +=.
                    I guess it's a mater of opinion but I personally don't like when something is adding paths or links libraries in my project without me telling it to. I would go as far as to stop qmake from always adding the core module so I wouldn't have to write Qt -= core in non-Qt qmake projects.

                    The thing you propose - automatic linking libraries based on include statements - while possible, this would be difficult (and posssibly slow on large projects?) to get right. And what if you only wanted some enum definition and by including single header you got linker to throw in a whole module or bunch of them? Nah, sounds nasty to me...

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      sinedie
                      wrote on last edited by
                      #10

                      I concur. :)

                      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