Results 1 to 4 of 4

Thread: Q_DECL_EXPORT and Q_DECL_IMPORT

  1. #1
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Q_DECL_EXPORT and Q_DECL_IMPORT

    I had a look at the edyuk's svn link to qcumber posted by fullmetalcoder and found these (@fullmetalcoder: Hope you don't mind me posting this here )

    Qt Code:
    1. #ifdef _QCUMBER_BUILD_
    2. #if (defined(QT_DLL) || defined(QT_SHARED)) && !defined(QT_PLUGIN)
    3. #define QCUMBER_EXPORT Q_DECL_EXPORT
    4. #else
    5. #define QCUMBER_EXPORT
    6. #endif
    7. #else
    8. #define QCUMBER_EXPORT Q_DECL_IMPORT
    9. #endif
    To copy to clipboard, switch view to plain text mode 

    I didn't understand this and tried searching in assistant for definition of Q_DECL_EXPORT and IMPORT but in vain. Then i looked at qglobal.h and found these macros defined to one of these based on some variable
    Qt Code:
    1. __declspec(dllexport),__attribute__((visibility("default"))),__declspec(dllimport)
    To copy to clipboard, switch view to plain text mode 

    Again i didn't understand. Googling didn't help much either since i don't even know the basics of this.
    Can someone help me understand this clearly ?
    And also can you tell me how this macro helps when used like this ?
    Qt Code:
    1. class Q_DECL_EXPORT SomeClass : BaseClass
    2. {
    3. ..
    4. };
    To copy to clipboard, switch view to plain text mode 
    Finally (probably to fullmetalcoder)
    Why is the QCUMBER_EXPORT defined to be Q_DECL_IMPORT ? (export - import )
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Q_DECL_EXPORT and Q_DECL_IMPORT

    Quote Originally Posted by Gopala Krishna View Post
    Can someone help me understand this clearly ?
    It's M$ idea. When you write DLLs, you have to explicitly mark objects (functions, classes or variables) that should be visible from the outside and you do this with __declspec(dllexport) tag. All other objects won't be accessible from the outside and only DLL code will be able to use them.

    Using GCC and other Unix compilers you can do the same with linker scripts (or __attribute__ tag), so you don't need funny macros.

    Quote Originally Posted by Gopala Krishna View Post
    Why is the QCUMBER_EXPORT defined to be Q_DECL_IMPORT ? (export - import )
    Because an object has to be exported when you compile the library and imported when you use the library. That's why you need a macro that is once Q_DECL_EXPORT and once Q_DECL_IMPORT.

  3. The following user says thank you to jacek for this useful post:

    Gopala Krishna (7th July 2007)

  4. #3
    Join Date
    May 2007
    Posts
    5
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Q_DECL_EXPORT and Q_DECL_IMPORT

    __declspec(dllexport) and __declspec(dllimport) are both used for creating dynamic library modules. It tells the compiler to make a symbol so that the program calling the library is able to find and execute the function/class/ect. Defining import does exactly the opposite... it is used in the calling application and tells the compiler the code is external. Sorry if that doesn't make much sense/help out at the moment, 4am here =P. Try this article (series of 4), it does a decent job.

    http://www.codeproject.com/dll/Dllfun.asp

    The QCUMBER_EXPORT define serves as an ease of use feature. Instead of having to keep two seperate copies of the .h file or change between export/import, we can let the compiler decide which one to use. In the QCumber project you're wanting to export the code from, you'd define _QCUMBER_BUILD_ in the preprocessor flags. Then when its including by other projects, it'll automatically be set to import.

    EDIT: Jacek beat me too it, and with clearly much more sleep ;-).

  5. The following user says thank you to daracne for this useful post:

    Gopala Krishna (7th July 2007)

  6. #4
    Join Date
    Aug 2006
    Location
    Bangalore,India
    Posts
    419
    Thanks
    37
    Thanked 53 Times in 40 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Q_DECL_EXPORT and Q_DECL_IMPORT

    Thanks for those nice overviews
    The biggest difference between time and space is that you can't reuse time.
    -- Merrick Furst

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.