Results 1 to 3 of 3

Thread: includes from headers

  1. #1
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default includes from headers

    Do any of you know of any smart tool that can extract include files out of headers. So that private members and other data irrelevant for usage og my libraray doesnt get installed

  2. #2
    Join Date
    Jul 2006
    Location
    Catalunya - Spain
    Posts
    117
    Thanks
    16
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: includes from headers

    I don't know any tool like that, sincerely. Anyway I will try to answer your question. I'm not sure to understand you, so correct me if I'm wrong.

    You want to take out methods & members of private section's of classes ? That will change class signature and nobody could link against your library !

    Perhaps, you have to do a *manual* cleanup of your classes, putting all private ( or irrelevant to the final user ) members & methods in a private class & out of public headers. Have you heard about pimpl idiom ? See the wiki, It's a good beginning.

    Using pimpl, It's a good approach to write libraries. I'm using an strategy like this in a big project I'm working on and makes me live happier . I usually create 3 files for each class :

    * Class.h => Public interface, with the minimal includes I can put in it. That means : if I don't have to instantiate an object of that class, i don't have to #include it's header. As an example :

    Qt Code:
    1. #include <BaseClass>
    2. Class A;
    3. Class B_Private;
    4.  
    5. Class B : public BaseClass // <== I HAVE TO #include, of course
    6. {
    7. // PIMPL zone...
    8. B_Private * d_ptr;
    9. Q_DECLARE_PRIVATE(B_Private);
    10.  
    11. public :
    12.  
    13. B();
    14. ~B();
    15.  
    16. void foo ( const A & Data ) const; // <== I DON'T HAVE TO #include
    17. }
    To copy to clipboard, switch view to plain text mode 

    * ClassB_p.h : declaration of private class, that hides implementation. Those headers doesn't have to be deployed, of course. And you can always put some code to forbid using those headers :

    Qt Code:
    1. #if !defined(__INTO_MYLIBRARY__)
    2. #error "This File is only for MYLIBRARY internal use !!"
    3. #endif
    To copy to clipboard, switch view to plain text mode 

    Defining __INTO_MYLIBRARY__ into your library's .pro file it's enough to allow you to re-compile the library.

    * Class.cpp : implementation of public & private parts of the class. Here I make the major part of #includes, as needed. At least, this pair

    Qt Code:
    1. #include "ClassB.h"
    2. #include "ClassB_p.h"
    3.  
    4. ( ... implementation ... )
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2009
    Posts
    14
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: includes from headers

    Thanks. That excactly what i need. I wasnt aware that changin the header would make it useless.

Similar Threads

  1. Where are those headers?
    By yagabey in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 17th January 2009, 17:29
  2. Pro->Makefile: how to make includes
    By Sergei82 in forum Qt Programming
    Replies: 2
    Last Post: 7th May 2008, 08:28
  3. deleting selected headers
    By ru_core in forum Qt Programming
    Replies: 3
    Last Post: 16th April 2008, 08:53
  4. Doubt about includes
    By xEsk in forum Newbie
    Replies: 2
    Last Post: 15th November 2007, 21:20
  5. How to make headers fixed sized? (QTableWidget)
    By macias in forum Qt Programming
    Replies: 4
    Last Post: 13th August 2007, 16:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.