乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Qt使用預(yù)處理文件

       牛人的尾巴 2016-12-13
      2013-01-22 11:22 1988人閱讀 評論(0) 收藏 舉報
      分類:

      參考1:Qt SDK手冊的Using Precompiled Headers一節(jié);

        

      預(yù)編譯就是編譯一部分代碼編譯為一個穩(wěn)定的二進(jìn)制文件。在編譯其余代碼的時候,編譯器會加載已經(jīng)保存該二進(jìn)制文件。編譯余下代碼的時候不需要重復(fù)編譯預(yù)編譯文件,這樣就加快的編譯過程。

       

      • Windows
        • nmake
        • Dsp projects (VC 6.0)
        • Vcproj projects (VC 7.0 & 7.1)
      • Mac OS X
        • Makefile
        • Xcode
      • Unix
        • GCC 3.4 and above

       

      1 在工程中添加預(yù)編譯文件

      1.1 預(yù)編譯文件的內(nèi)容

      預(yù)編譯最好包含穩(wěn)定的不易改變的代碼,一個典型的預(yù)編譯文件結(jié)構(gòu)如下:

      Example: stable.h

      //Add C includes here

       

       #if defined __cplusplus

       // 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

       

      請注意:該預(yù)編譯頭文件必須區(qū)分包含的C文件和C++文件,因?yàn)榘珻文件的預(yù)編譯文件不能包含C++文件。

       

       1.2 工程選項(xiàng)

      要使工程使用你的預(yù)處理文件,你需要加上如下的語句

      1. PRECOMPILED_HEADER = stable.h  

      qmake會做其余的工作。你不需要將stable.h包含到HEADERS中,因?yàn)楫?dāng)配置支持PCH的時候,qmake會自動幫你包含的該文件的。

      所有的平臺都支持預(yù)編譯文件選項(xiàng)precompile_header,你可以使用該選項(xiàng)來?xiàng)l件定義宏USING_PCH,代碼如下:

      1. precompile_header:!isEmpty(PRECOMPILED_HEADER) {  
      2. DEFINES += USING_PCH  
      3. }  

      2. 可能出現(xiàn)的問題

      在某些平臺,預(yù)編譯的文件后綴名很可能和其他文件名稱相同。例如,下面的代碼可能會生成相同的中間文件。

      1. PRECOMPILED_HEADER = window.h  
      2. SOURCES            = window.cpp  

      為了避免這些,最好就是給預(yù)編譯頭文件一個獨(dú)一無二的名稱。


      /////////////////////////////////////////////////////

      // 這部分我沒使用文檔里面的例子,那個還不夠簡單,我這個更簡單易懂。

      3. 例子代碼

      1. stable.h  
      2. #ifndef STABLE_H  
      3. #define STABLE_H  
      4.   
      5. /* Add C includes here */  
      6.   
      7. #if defined __cplusplus  
      8. /* Add C++ includes here */  
      9. #include <QWidget>  
      10. #endif  
      11.   
      12. #endif // STABLE_H  

      1. widget.h  
      2. #ifndef WIDGET_H  
      3. #define WIDGET_H  
      4.   
      5. <pre name="code" class="cpp">//#include <QWidget></pre><p></p>  
      6. <pre></pre>  
      7. <pre name="code" class="cpp">// 我這里故意將該句注釋,倘若你添加預(yù)編譯文件stable.h,肯定會出現(xiàn)</pre><pre name="code" class="cpp">錯誤:C2504: 'QWidget' : base class undefined</pre><pre name="code" class="cpp">namespace Ui {  
      8. class Widget;  
      9. }  
      10.   
      11. class Widget : public QWidget  
      12. {  
      13.     Q_OBJECT  
      14.       
      15. public:  
      16.     explicit Widget(QWidget *parent = 0);  
      17.     ~Widget();  
      18.       
      19. private:  
      20.     Ui::Widget *ui;  
      21. };  
      22.   
      23. #endif // WIDGET_H</pre><br>  
      24. 下面是<pre name="code" class="cpp">widget.cpp  
      25.   
      26. #include "widget.h"  
      27. #include "ui_widget.h"  
      28.   
      29. Widget::Widget(QWidget *parent) :  
      30.     QWidget(parent),  
      31.     ui(new Ui::Widget)  
      32. {  
      33.     ui->setupUi(this);  
      34. }  
      35.   
      36. Widget::~Widget()  
      37. {  
      38.     delete ui;  
      39. }</pre>最后是  
      40. <p></p>  
      41. <p></p><pre name="code" class="cpp">main.cpp  
      42.   
      43. #include "widget.h"  
      44. #include <QApplication>  
      45.   
      46. int main(int argc, char *argv[])  
      47. {  
      48.     QApplication a(argc, argv);  
      49.     Widget w;  
      50.     w.show();  
      51.       
      52.     return a.exec();  
      53. }</pre><br>  
      54. <br>  
      55. <p></p>  
      56. <p><br>  
      57. </p>  
      58. <p><br>  
      59. </p>  
      60. <p> </p>  
      61. <p> </p>  
      62. <p> </p>  
      63. <p> </p>  
      64. <p> </p>  
      65. <p> </p>  
      66. <p> </p>  
      67. <p> </p>  
      68. <p> </p>  
      69. <p> </p>  
      70. <p> </p>  
      71. <p> </p>  
      72. <p> </p>  
      73. <p> </p>  
      74. <p> </p>  
      75. <p> </p>  
      76. <p> </p>  
      77. <p> </p>  
      78. <p> </p>  
      79. <p> </p>  
      80. <p> </p>  
      81. <p> </p>  
      82.      

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多