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. QMake precompiled headers in *.pri files. How?

QMake precompiled headers in *.pri files. How?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 609 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.
  • B Offline
    B Offline
    bogong
    wrote on last edited by
    #1

    Hello all!

    The project contain many modules that descibed in *.pri files. Each of them has some headers for being precompiled. Trying to find the correct way of using precompiled headers in case of multiple *.pri files. In all of official documentation nothing about it. The example described in it just with one *.pro file without any includes *.pri

    The questions is:

    -- the QMake variable named PRECOMPILED_HEADER, does it mean one header file or it could be using for multiple files in different places or in different *.pri files, something like this:

    PRECOMPILED_HEADER += header1.h
    ...
    PRECOMPILED_HEADER += header2.h
    

    -- Some of examples from KDAB contain "#pragma once" and it's about CMake. Official documentation is nothing about it? Should it be using with pragma in QMake too? Something like this:

    // Add C includes here
    
    #if defined __cplusplus
    
    #pragma once 
    
    // Add C++ includes here
    #include <stdlib>
    #include <iostream>
    #include <vector>
    #include <QApplication> // Qt includes
    #include <QPushButton>
    #include <QLabel>
    #include "thirdparty/include/libmain.h"
    #include "my_stable_class.h"
    ...
    #endif
    
    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by Chris Kawa
      #2

      does it mean one header file or it could be using for multiple files in different places

      Unfortunately qmake doesn't support multiple precompiled headers in a single project. Only the first file in PRECOMPILED_HEADER will be used. You can have different precompiled headers if you use a subdirs project, where each subdir would be its own library with its own header, or you can make a single header and include all the rest in it.

      Some of examples from KDAB contain "#pragma once" and it's about CMake. Official documentation is nothing about it? Should it be using with pragma in QMake too?

      It has nothing to do with CMake or qmake. #pragma once is a compiler extension that replaces include guards i.e. in a standard C++ you would create headers like this:

      #ifndef MYHEADER_H
      #define MYHEADER_H
      //something something
      #endif
      

      with this extension you can simplify this to

      #pragma once
      //something something
      

      There are small differences in the behavior of these two in some corner cases, but for normal usage they are equivalent. Whether you use one or the other is up to you. All major compilers support this, so it's just your decision if you're ok with using language extension.

      B 1 Reply Last reply
      1
      • Chris KawaC Chris Kawa

        does it mean one header file or it could be using for multiple files in different places

        Unfortunately qmake doesn't support multiple precompiled headers in a single project. Only the first file in PRECOMPILED_HEADER will be used. You can have different precompiled headers if you use a subdirs project, where each subdir would be its own library with its own header, or you can make a single header and include all the rest in it.

        Some of examples from KDAB contain "#pragma once" and it's about CMake. Official documentation is nothing about it? Should it be using with pragma in QMake too?

        It has nothing to do with CMake or qmake. #pragma once is a compiler extension that replaces include guards i.e. in a standard C++ you would create headers like this:

        #ifndef MYHEADER_H
        #define MYHEADER_H
        //something something
        #endif
        

        with this extension you can simplify this to

        #pragma once
        //something something
        

        There are small differences in the behavior of these two in some corner cases, but for normal usage they are equivalent. Whether you use one or the other is up to you. All major compilers support this, so it's just your decision if you're ok with using language extension.

        B Offline
        B Offline
        bogong
        wrote on last edited by
        #3

        @Chris-Kawa said in QMake precompiled headers in *.pri files. How?:

        It has nothing to do with CMake or qmake. #pragma once is a compiler extension that replaces include guards i.e. in a standard C++

        That's interesting about #pragma once. Never been using it. For the more than 10 years of Qt developing got it from you for the first time. Definetly need to refresh reading of compiler reference. Thanks a lot for explanation.

        Issue closed.

        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