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. #include with the .h or without
Qt 6.11 is out! See what's new in the release blog

#include with the .h or without

Scheduled Pinned Locked Moved General and Desktop
7 Posts 6 Posters 6.3k Views 4 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.
  • TheBadgerT Offline
    TheBadgerT Offline
    TheBadger
    wrote on last edited by
    #1

    Hi,

    I see in general the Qt headers are included using #include <QtHeader> instead of #include <QtHeader.h>.
    Are there any reasons for using the one above the other?


    Check out my SpellChecker Plugin for Qt Creator @ https://github.com/CJCombrink/SpellChecker-Plugin

    1 Reply Last reply
    1
    • S Offline
      S Offline
      svyatoslav911512
      wrote on last edited by svyatoslav911512
      #2

      I believe there is doesn't matter on how you specified name in angle brackets. Following by C++ notation it maters only if you specified header name in angle brackets or in quotes (it's changes order of source file searching). Actually you should use angle brackets with header name, than filename in quotes. It's the main difference.

      Answer for your particular question is there:

      user@laptop:/usr/include/qt4/QtCore$ cat QMimeData
      #include "qmimedata.h"
      user@laptop:/usr/include/qt4/QtCore$ head qmimedata.h
      /****************************************************************************
      **
      ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
      ** Contact: http://www.qt-project.org/legal
      **
      ** This file is part of the QtCore module of the Qt Toolkit.
      **
      ** $QT_BEGIN_LICENSE:LGPL$
      ** Commercial License Usage
      ** Licensees holding valid commercial Qt licenses may use this file in
      user@laptop:/usr/include/qt4/QtCore$

      <QtHeader> it's file too, with some set of #include directives, while <QtHeader.h> could be file exacty related to your question like "qtheader.h" without any additional includes.

      Thanks
      Svyatoslav

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        @TheBadger I believe both forms #include <QObject> and #include <qobject.h>are okay. Note the difference in case. This matters on some platforms.

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

          Good one link on Stackoverflow

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

            Hi,

            Using the h-less header set is more complete in terms of class names. You can have several classes coming from the same .h file e.g. QVBoxLayout, QHBoxLayout both come from qboxlayout.h however using #include <QVBoxLayout> makes you intention clearer in your code. Another advantage of doing so is that if a class was to be moved to another header for whatever reason, then your application would still be able to build.

            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

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

              From the C++ standpoint it's purely a matter of paths to be searched.
              But a lot more important here is that the .h headers are considered Qt internal and are subject to change without notice (no Qt documentation mentions them if I'm not mistaken), while the .h-less ones are considered publicly maintained API of Qt.

              1 Reply Last reply
              1
              • N Offline
                N Offline
                nejatafshar
                wrote on last edited by
                #7

                One benefit of using Qt header files without extensions is that it separates your custom header files from Qt ones in some way. It makes it more clear and clean that which header is for Qt and which one is yours.

                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