From d796c9dd933ab96ec83b9a634feedd5d32e1ba3f Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Tue, 8 Nov 2011 12:31:36 -0600 Subject: Test conversion to TQt3 from Qt3 8c6fc1f8e35fd264dd01c582ca5e7549b32ab731 --- doc/html/qmake-manual-7.html | 206 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 206 insertions(+) create mode 100644 doc/html/qmake-manual-7.html (limited to 'doc/html/qmake-manual-7.html') diff --git a/doc/html/qmake-manual-7.html b/doc/html/qmake-manual-7.html new file mode 100644 index 000000000..8c71e939f --- /dev/null +++ b/doc/html/qmake-manual-7.html @@ -0,0 +1,206 @@ + + + + + +Using Precompiled Headers + + + + + + + +
+ +Home + | +All Classes + | +Main Classes + | +Annotated + | +Grouped Classes + | +Functions +

[Prev: qmake's Advanced Concepts] [Home] [Next: qmake Command Reference]

+

Using Precompiled Headers

+

About Precompiled Headers

+

Precompiled headers are a performance feature supported by some compilers to compile a stable body of code, and store the compiled state of the code in a binary file. During subsequent compilations, the compiler will load the stored state, and continue compiling the specified file. Each subsequent compilation is faster because the stable code does not need to be recompiled.

+

qmake supports the use of precompiled headers (PCH) on some platforms and build environments, including:

+

Adding PCH to your project

+

Contents of the precompiled header file

+

The precompiled header must contain code which is stable and static throughout your project. A typical PCH might look like this:

+
stable.h
+
+        /* Add C includes here */
+        
+        #if defined __cplusplus
+        /* Add C++ includes here */
+        #include <stdlib>
+        #include <iostream>
+        #include <vector>
+        #include <qapplication.h> // TQt includes
+        #include <qpushbutton.h>
+        #include <qlabel.h>
+        #include "thirdparty/include/libmain.h"
+        #include "my_stable_class.h"
+        ...
+        #endif
+
+

Note that a precompiled header file needs to separate C includes from CPP includes, since the precompiled header file for C files may not contain C++ code.

+

Project options

+

To make your project use PCH, the only thing you need to change in your project settings (.pro), is to include the PRECOMPILED_HEADER option:

+
+        PRECOMPILED_HEADER = stable.h
+
+

qmake will handle the rest, to ensure the creation and use of the precompiled header file. You do not need to include the precompiled header file in HEADERS, as qmake will do this if the configuration supports PCH.

+

All platforms that support precompiled headers have the configuration option precompile_header set. Using this option, you may trigger conditional blocks in your .pro file, to add settings when using PCH. For example:

+
+        precompile_header:!isEmpty(PRECOMPILED_HEADER) {
+            DEFINES += USING_PCH
+        }
+
+
+

Example project

+

You can find the following source code in the qt/qmake/examples/precompile directory:

+

mydialog.ui

+
    <!DOCTYPE UI><UI version="3.3" stdsetdef="1">
+    <class>MyDialog</class>
+    <widget class="TQDialog">
+        <property name="name">
+            <cstring>MyDialog</cstring>
+        </property>
+        <property name="caption">
+            <string>Mach 2!</string>
+        </property>
+        <vbox>
+            <widget class="TQLabel">
+                <property name="name">
+                    <cstring>aLabel</cstring>
+                </property>
+                <property name="text">
+                    <string>Join the life in the fastlane; - PCH enable your project today! -</string>
+                </property>
+            </widget>
+            <widget class="TQPushButton">
+                <property name="name">
+                    <cstring>aButton</cstring>
+                </property>
+                <property name="text">
+                    <string>&amp;Quit</string>
+                </property>
+                <property name="accel">
+                    <string>Alt+Q</string>
+                </property>
+            </widget>
+        </vbox>
+    </widget>
+    </UI>
+
+

stable.h

+
    /* Add C includes here */
+
+    #if defined __cplusplus
+    /* Add C++ includes here */
+
+    # include <iostream>
+    # include <qapplication.h>
+    # include <qpushbutton.h>
+    # include <qlabel.h>
+    #endif
+
+

myobject.h

+
    #include <qobject.h>
+
+    class MyObject : public TQObject
+    {
+    public:
+        MyObject();
+        ~MyObject();
+    };
+
+

myobject.cpp

+
    #include <iostream>
+    #include <qobject.h>
+    #include "myobject.h"
+
+    MyObject::MyObject()
+        : TQObject()
+    {
+        std::cout << "MyObject::MyObject()\n";
+    }
+
+

util.cpp

+
    void util_function_does_nothing()
+    {
+        // Nothing here...
+        int x = 0;
+        ++x;
+    }
+
+

main.cpp

+
    #include <qapplication.h>
+    #include <qpushbutton.h>
+    #include <qlabel.h>
+    #include "myobject.h"
+    #include "mydialog.h"
+
+    int main(int argc, char **argv)
+    {
+        TQApplication app(argc, argv);
+
+        MyObject obj;
+        MyDialog dia;
+        app.setMainWidget( &dia );
+        dia.connect( dia.aButton, SIGNAL(clicked()), SLOT(close()) );
+        dia.show();
+
+        return app.exec();
+    }
+
+

precompile.pro

+
    #############################################
+    #
+    # Example for using Precompiled Headers
+    #
+    #############################################
+    TEMPLATE  = app
+    LANGUAGE  = C++
+    CONFIG   += console precompile_header
+
+    # Use Precompiled headers (PCH)
+    PRECOMPILED_HEADER  = stable.h
+
+    HEADERS  += stable.h \
+                myobject.h
+    SOURCES  += main.cpp \
+                myobject.cpp \
+                util.cpp
+    FORMS     = mydialog.ui
+
+ +

[Prev: qmake's Advanced Concepts] [Home] [Next: qmake Command Reference]

+


+ +
Copyright © 2007 +TrolltechTrademarks +
TQt 3.3.8
+
+ -- cgit v1.2.1