Q_DECL_EXPORT keyword meaning

20,403

Solution 1

Excerpt from QT docs:

Depending on your target platform, Qt provides special macros that contain the necessary definitions:

  • Q_DECL_EXPORT must be added to the declarations of symbols used when compiling a shared library.
  • Q_DECL_IMPORT must be added to the declarations of symbols used when compiling a client that uses the shared library.

I haven't check the QT code, but most likely this macro will do following:

#ifdef _WIN32 || _WIN64
    #define Q_DECL_EXPORT __declspec(dllexport)
    #define Q_DECL_IMPORT __declspec(dllimport)
#else
    #define Q_DECL_EXPORT
    #define Q_DECL_IMPORT
#endif

__declspec(dllimport) and __declspec(dllexport) tells the linker to import and export (respectively) a symbol from or to a DLL. This is Windows specific.

In your particular case this macro probably could be removed, since main() most likely is not part of a library.

Solution 2

Its not a keyword, its a macro to encapsulate the different compiler specific keywords to declare a function as being exported.

See also Q_DECL_EXPORT and Creating Shared Libraries.

It is usually used with libraries to define those functions which need to be exported from the library, in order to be imported ("used") by other libraries or by executables.

I have not seen this with a main function so far, but that could be a blackberry specific thing. On the other hand, this tutorial does not use the macro with the main() function either, so it can probably be removed.

Share:
20,403

Related videos on Youtube

Tahlil
Author by

Tahlil

Professional C++ developer working as a Senior Software Engineer at Abukai Inc. Working on Computer Vision. Artificial Intelligence enthusiastic, Very passionate about Machine Learning.

Updated on November 03, 2020

Comments

  • Tahlil
    Tahlil over 3 years

    Q_DECL_EXPORT int main(int argc, char **argv)

    What does this Q_DECL_EXPORT before int main(...) means?

  • tanius
    tanius about 4 years
    Q_DECL_EXPORT main() is necessary when building Qt applications for Android, as native Android applications are loaded as a library from bootstrap Java code. It might have been similar under Blackberry, I don't know.