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. Including <QtGui/...> or <...>
QtWS25 Last Chance

Including <QtGui/...> or <...>

Scheduled Pinned Locked Moved General and Desktop
11 Posts 6 Posters 12.2k Views
  • 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.
  • P Offline
    P Offline
    Plissken
    wrote on last edited by
    #1

    I noticed many of the classes in Qt are copied in different directories. At first I thought gui related widgets were only located in <QtGui/...> but many of the classes in QtGui are copied over in <Qt> folder. Does it matter which one we use?

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tobias.hunger
      wrote on last edited by
      #2

      No, it does not. Both <Module/Class> and <Class> should include the same file since the include path will contain both "toplevel/Qt" as well as "toplevel/Qt/Module" (at least when using qmake projects).

      In creator we used to do <QtGui/QLabel> to make explicit which modules we were using. With Qt5 being started and with it moving around classes we switched to <QLabel> style includes to allow building Creator with both Qt4 and Qt5.

      1 Reply Last reply
      0
      • G Offline
        G Offline
        giesbert
        wrote on last edited by
        #3

        I prefer the Module/class style as it clearly shows which modules I am using.
        And if you work with MSVS or other compilers, it also works with setting only one include path.

        Nokia Certified Qt Specialist.
        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

        1 Reply Last reply
        0
        • I Offline
          I Offline
          issam
          wrote on last edited by
          #4

          When using qmake (and this is the best method), I suggest to use <module>. For example, in your main.cpp add this line :

          #include<QtGui>

          and in the qMakefile add those 2 lines :

          CONFIG += qt
          QT += gui

          the qmake will generate the appropriate Makefile and you will not find any problem :)

          http://www.iissam.com/

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            [quote author="issam" date="1342372394"]#include<QtGui>
            [/quote]
            This has some disadvantages as it includes all headers which has an impact on the compile time.
            I prefer to include only what is needed and if possible only in cpp files and in headers use forward declarations.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • sierdzioS Offline
              sierdzioS Offline
              sierdzio
              Moderators
              wrote on last edited by
              #6

              [quote author="issam" date="1342372394"]When using qmake (and this is the best method), I suggest to use <module>. For example, in your main.cpp add this line :

              #include<QtGui>
              [/quote]

              This is quite suboptimal, the compilation will take longer if you include the whole module. I know it's harder, but when you include just what you need, the compiler has less stuff to parse. I've recently optimised headers in that manner in a project I'm responsible for, and compilation sped up by about 40%.

              (Z(:^

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #7

                [quote author="issam" date="1342372394"]
                @
                #include<QtGui>
                @
                [/quote]

                Please don't do that. It makes your project slow to compile, and it makes it harder to see what is actually used by your class. Furthermore, this style of "just include everything" can cause hard to fix compilation issues (unneeded interdepencies between files) if you also apply it to your own code. Just include what you actually need, but please do include everything you use (even if it also works without). You don't want your compilation to rely on the fact that some other header you included already includes QString because of some internal need for it. As soon as you change that latter class and you remove the include there, the other file that relied on it will stop compiling. That is just plain annoying.

                1 Reply Last reply
                0
                • I Offline
                  I Offline
                  issam
                  wrote on last edited by
                  #8

                  I know dear friends ... But I think that this method is suitable for small Qt projects !
                  Isn't ?

                  http://www.iissam.com/

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    No, it may be usable for quick demo's an wips, but not for anything you plan to distrubute and maintain for any amount of time. What starts as (a component in) a small project may end up as (a component in) a big project. So, for the general case, I think it is bad advice to give. It doesn't really help you either. How much work is it to just #include the actual classes you're using anyway?

                    1 Reply Last reply
                    0
                    • sierdzioS Offline
                      sierdzioS Offline
                      sierdzio
                      Moderators
                      wrote on last edited by
                      #10

                      Well, if you don't stick to including specific headers from the start, and your project is ongoing, it will come to a point (sooner or later) where you will be facing long compilation times and a big effort to fix it. In the optimisation job I've mentioned, I had to look through well over a hundred source and header files and fix them all. It took about 3 days to complete.

                      So, while you are right that it's not necessary, especially for small projects where compilation time is negligible anyway, it sure is easier to do it right from the very start than to be forced to fix it later.

                      (Z(:^

                      1 Reply Last reply
                      0
                      • I Offline
                        I Offline
                        issam
                        wrote on last edited by
                        #11

                        All right, I surrender :)
                        and I will confess : In my project I began by this :

                        @# include <QtGui>@

                        And I ended by :

                        @
                        #include <QDebug>
                        #include <QApplication>
                        #include <QDesktopWidget>
                        #include <QPushButton>
                        #include <QLineEdit>
                        #include <QHBoxLayout>
                        #include <QVBoxLayout>
                        #include <QGridLayout>
                        #include <QTabWidget>
                        #include <QWizard>
                        #include <QWizardPage>
                        #include <QTableView>
                        #include <QListView>
                        #include <QStringListModel>
                        #include <QStandardItemModel>
                        #include <QFrame>
                        #include <QGroupBox>
                        #include <QMessageBox>
                        #include <QInputDialog>
                        #include <QLabel>
                        @

                        It's hard to me but very easy to the compiler ... very easy !

                        http://www.iissam.com/

                        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