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 use precompiled headers (pch) for C++ with Qt

How to use precompiled headers (pch) for C++ with Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.0k 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.
  • J Offline
    J Offline
    JacobNovitsky
    wrote on 12 Oct 2023, 02:14 last edited by
    #1

    Tried to google a little, but information is not much consistent...
    Need to build faster my custom headers and Qt core/gui/widgets headers too

    C 1 Reply Last reply 12 Oct 2023, 03:54
    0
    • J JacobNovitsky
      12 Oct 2023, 02:14

      Tried to google a little, but information is not much consistent...
      Need to build faster my custom headers and Qt core/gui/widgets headers too

      C Offline
      C Offline
      ChrisW67
      wrote on 12 Oct 2023, 03:54 last edited by
      #2

      qmake: Using Precompiled Headers
      cmake: target_precompile_headers

      J 1 Reply Last reply 12 Oct 2023, 09:23
      3
      • C ChrisW67
        12 Oct 2023, 03:54

        qmake: Using Precompiled Headers
        cmake: target_precompile_headers

        J Offline
        J Offline
        JacobNovitsky
        wrote on 12 Oct 2023, 09:23 last edited by JacobNovitsky 10 Dec 2023, 09:29
        #3

        @ChrisW67 thanks :)
        do you have real code sample I could refer to?

        as I can see the process, I need to insert

        /* Add C includes here */
        
        #if defined __cplusplus
        /* Add C++ includes here */
        
        # include <iostream>
        # include <QApplication>
        # include <QPushButton>
        # include <QLabel>
        #endif
        

        before every qt header and add smth to qt pro file?

        M 1 Reply Last reply 12 Oct 2023, 11:48
        0
        • J JacobNovitsky
          12 Oct 2023, 09:23

          @ChrisW67 thanks :)
          do you have real code sample I could refer to?

          as I can see the process, I need to insert

          /* Add C includes here */
          
          #if defined __cplusplus
          /* Add C++ includes here */
          
          # include <iostream>
          # include <QApplication>
          # include <QPushButton>
          # include <QLabel>
          #endif
          

          before every qt header and add smth to qt pro file?

          M Offline
          M Offline
          mpergand
          wrote on 12 Oct 2023, 11:48 last edited by mpergand 10 Dec 2023, 11:55
          #4

          @JacobNovitsky
          Here my own example:

          .pro file

          CONFIG +=   precompile_header
          PRECOMPILED_HEADER = $$PWD/Application/Headers.pch
          

          Headers.pch

          // Prefix header 
          
          #ifdef __cplusplus
          										
          #include "QtMacros.h"
          #include "QtAppDefs.h"
          
          #endif
          

          And you don't need to insert anything in your .h .cpp files.

          J 1 Reply Last reply 15 Oct 2023, 03:45
          3
          • M mpergand
            12 Oct 2023, 11:48

            @JacobNovitsky
            Here my own example:

            .pro file

            CONFIG +=   precompile_header
            PRECOMPILED_HEADER = $$PWD/Application/Headers.pch
            

            Headers.pch

            // Prefix header 
            
            #ifdef __cplusplus
            										
            #include "QtMacros.h"
            #include "QtAppDefs.h"
            
            #endif
            

            And you don't need to insert anything in your .h .cpp files.

            J Offline
            J Offline
            JacobNovitsky
            wrote on 15 Oct 2023, 03:45 last edited by
            #5

            @mpergand is it nessesary to change .h to .pch or I can use .h file too?

            C 1 Reply Last reply 15 Oct 2023, 06:00
            0
            • J JacobNovitsky
              15 Oct 2023, 03:45

              @mpergand is it nessesary to change .h to .pch or I can use .h file too?

              C Offline
              C Offline
              ChrisW67
              wrote on 15 Oct 2023, 06:00 last edited by
              #6

              @JacobNovitsky Call the file whatever you like.

              J 1 Reply Last reply 15 Oct 2023, 06:20
              1
              • J JacobNovitsky referenced this topic on 15 Oct 2023, 06:20
              • C ChrisW67
                15 Oct 2023, 06:00

                @JacobNovitsky Call the file whatever you like.

                J Offline
                J Offline
                JacobNovitsky
                wrote on 15 Oct 2023, 06:20 last edited by
                #7

                @ChrisW67 how to test if its already pre-compiled, my complier does not compile this particular header?
                https://forum.qt.io/topic/151001/additional-info-upon-compiling-with-qt-creator

                C 1 Reply Last reply 15 Oct 2023, 06:51
                0
                • J JacobNovitsky
                  15 Oct 2023, 06:20

                  @ChrisW67 how to test if its already pre-compiled, my complier does not compile this particular header?
                  https://forum.qt.io/topic/151001/additional-info-upon-compiling-with-qt-creator

                  C Offline
                  C Offline
                  ChrisW67
                  wrote on 15 Oct 2023, 06:51 last edited by
                  #8

                  @JacobNovitsky Please stop creating new threads for the same conversation.

                  C 1 Reply Last reply 15 Oct 2023, 07:30
                  1
                  • C ChrisW67 referenced this topic on 15 Oct 2023, 07:21
                  • C Christian Ehrlicher referenced this topic on 15 Oct 2023, 07:29
                  • C ChrisW67
                    15 Oct 2023, 06:51

                    @JacobNovitsky Please stop creating new threads for the same conversation.

                    C Offline
                    C Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 15 Oct 2023, 07:30 last edited by
                    #9

                    Dupe of https://forum.qt.io/topic/150964/how-to-set-needed-permission-so-i-can-edit-qt-headers-from-qt-creator/6

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    1 Reply Last reply
                    1
                    • C Christian Ehrlicher locked this topic on 15 Oct 2023, 07:30

                    3/9

                    12 Oct 2023, 09:23

                    6 unread
                    • Login

                    • Login or register to search.
                    3 out of 9
                    • First post
                      3/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved