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
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.2k Views 2 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.
  • J Offline
    J Offline
    JacobNovitsky
    wrote on 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
    0
    • J JacobNovitsky

      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 last edited by
      #2

      qmake: Using Precompiled Headers
      cmake: target_precompile_headers

      J 1 Reply Last reply
      3
      • C ChrisW67

        qmake: Using Precompiled Headers
        cmake: target_precompile_headers

        J Offline
        J Offline
        JacobNovitsky
        wrote on last edited by JacobNovitsky
        #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
        0
        • J JacobNovitsky

          @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 last edited by mpergand
          #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
          3
          • M mpergand

            @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 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
            0
            • J JacobNovitsky

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

              C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              @JacobNovitsky Call the file whatever you like.

              J 1 Reply Last reply
              1
              • J JacobNovitsky referenced this topic on
              • C ChrisW67

                @JacobNovitsky Call the file whatever you like.

                J Offline
                J Offline
                JacobNovitsky
                wrote on 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
                0
                • J JacobNovitsky

                  @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 last edited by
                  #8

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

                  Christian EhrlicherC 1 Reply Last reply
                  1
                  • C ChrisW67 referenced this topic on
                  • Christian EhrlicherC Christian Ehrlicher referenced this topic on
                  • C ChrisW67

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

                    Christian EhrlicherC Online
                    Christian EhrlicherC Online
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on 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
                    • Christian EhrlicherC Christian Ehrlicher locked this topic on

                    • Login

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