Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. C2491: 'SmtpClient::staticMetaObject': definition of dllimport static data member not allowed
Forum Updated to NodeBB v4.3 + New Features

C2491: 'SmtpClient::staticMetaObject': definition of dllimport static data member not allowed

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 3 Posters 970 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Saee1101
    wrote on last edited by
    #1

    I have problem with SmtpClient for Qt in windows :

    QT_INIT_METAOBJECT const QMetaObject SmtpClient::staticMetaObject = { {
    QMetaObject::SuperData::linkQObject::staticMetaObject(),
    qt_meta_stringdata_SmtpClient.data,
    qt_meta_data_SmtpClient,
    qt_static_metacall,
    nullptr,
    nullptr
    } };
    I don't know what to do ?
    help me , please.

    Christian EhrlicherC 1 Reply Last reply
    0
    • S Saee1101

      I have problem with SmtpClient for Qt in windows :

      QT_INIT_METAOBJECT const QMetaObject SmtpClient::staticMetaObject = { {
      QMetaObject::SuperData::linkQObject::staticMetaObject(),
      qt_meta_stringdata_SmtpClient.data,
      qt_meta_data_SmtpClient,
      qt_static_metacall,
      nullptr,
      nullptr
      } };
      I don't know what to do ?
      help me , please.

      Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      please provide a minimal example of your problem. You show only sme generated code. I would guess you use declspec(dllexport)/declspec(dllimport) wrong.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      S 1 Reply Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher referenced this topic on
      • Christian EhrlicherC Christian Ehrlicher

        please provide a minimal example of your problem. You show only sme generated code. I would guess you use declspec(dllexport)/declspec(dllimport) wrong.

        S Offline
        S Offline
        Saee1101
        wrote on last edited by Saee1101
        #3

        @Christian-Ehrlicher
        qglobal.h :

        /****************************************************************************
        **
        ** Copyright (C) 2019 The Qt Company Ltd.
        ** Copyright (C) 2019 Intel Corporation.
        ** Contact: https://www.qt.io/licensing/
        **
        ** This file is part of the QtCore module of the Qt Toolkit.
        **
        ** $QT_BEGIN_LICENSE:LGPL$
        ** Commercial License Usage
        ** Licensees holding valid commercial Qt licenses may use this file in
        ** accordance with the commercial license agreement provided with the
        ** Software or, alternatively, in accordance with the terms contained in
        ** a written agreement between you and The Qt Company. For licensing terms
        ** and conditions see https://www.qt.io/terms-conditions. For further
        ** information use the contact form at https://www.qt.io/contact-us.
        **
        ** GNU Lesser General Public License Usage
        ** Alternatively, this file may be used under the terms of the GNU Lesser
        ** General Public License version 3 as published by the Free Software
        ** Foundation and appearing in the file LICENSE.LGPL3 included in the
        ** packaging of this file. Please review the following information to
        ** ensure the GNU Lesser General Public License version 3 requirements
        ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
        **
        ** GNU General Public License Usage
        ** Alternatively, this file may be used under the terms of the GNU
        ** General Public License version 2.0 or (at your option) the GNU General
        ** Public license version 3 or any later version approved by the KDE Free
        ** Qt Foundation. The licenses are as published by the Free Software
        ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
        ** included in the packaging of this file. Please review the following
        ** information to ensure the GNU General Public License requirements will
        ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
        ** https://www.gnu.org/licenses/gpl-3.0.html.
        **
        ** $QT_END_LICENSE$
        **
        ****************************************************************************/
        
        #ifndef QGLOBAL_H
        #define QGLOBAL_H
        
        #ifdef __cplusplus
        #  include <type_traits>
        #  include <cstddef>
        #  include <utility>
        #endif
        #ifndef __ASSEMBLER__
        #  include <assert.h>
        #  include <stddef.h>
        #endif
        
        /*
           QT_VERSION is (major << 16) + (minor << 8) + patch.
        */
        #define QT_VERSION      QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH)
        /*
           can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
        */
        #define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
        
        #ifdef QT_BOOTSTRAPPED
        #include <QtCore/qconfig-bootstrapped.h>
        #else
        #include <QtCore/qconfig.h>
        #include <QtCore/qtcore-config.h>
        #endif
        
        // The QT_SUPPORTS macro is deprecated. Don't use it in new code.
        // Instead, use QT_CONFIG(feature)
        // ### Qt6: remove macro
        #ifdef _MSC_VER
        #  define QT_SUPPORTS(FEATURE) (!defined QT_NO_##FEATURE)
        #else
        #  define QT_SUPPORTS(FEATURE) (!defined(QT_NO_##FEATURE))
        #endif
        
        /*
            The QT_CONFIG macro implements a safe compile time check for features of Qt.
            Features can be in three states:
                0 or undefined: This will lead to a compile error when testing for it
                -1: The feature is not available
                1: The feature is available
        */
        #define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
        #define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
        
        #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
        #  define QT_NO_UNSHARABLE_CONTAINERS
        #  define QT6_VIRTUAL virtual
        #  define QT6_NOT_VIRTUAL
        #else
        #  define QT6_VIRTUAL
        #  define QT6_NOT_VIRTUAL virtual
        #endif
        
        /* These two macros makes it possible to turn the builtin line expander into a
         * string literal. */
        #define QT_STRINGIFY2(x) #x
        #define QT_STRINGIFY(x) QT_STRINGIFY2(x)
        
        #include <QtCore/qsystemdetection.h>
        #include <QtCore/qprocessordetection.h>
        #include <QtCore/qcompilerdetection.h>
        
        #if defined (__ELF__)
        #  define Q_OF_ELF
        #endif
        #if defined (__MACH__) && defined (__APPLE__)
        #  define Q_OF_MACH_O
        #endif
        
        /*
           Avoid "unused parameter" warnings
        */
        #define Q_UNUSED(x) (void)x;
        
        #if defined(__cplusplus) && defined(Q_COMPILER_STATIC_ASSERT)
        #  define Q_STATIC_ASSERT(Condition) static_assert(bool(Condition), #Condition)
        #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
        #elif defined(Q_COMPILER_STATIC_ASSERT)
        // C11 mode - using the _S version in case <assert.h> doesn't do the right thing
        #  define Q_STATIC_ASSERT(Condition) _Static_assert(!!(Condition), #Condition)
        #  define Q_STATIC_ASSERT_X(Condition, Message) _Static_assert(!!(Condition), Message)
        #else
        // C89 & C99 version
        #  define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B)
        #  define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B
        #  ifdef __COUNTER__
        #  define Q_STATIC_ASSERT(Condition) \
            typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __COUNTER__) [(Condition) ? 1 : -1];
        #  else
        #  define Q_STATIC_ASSERT(Condition) \
            typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) [(Condition) ? 1 : -1];
        #  endif /* __COUNTER__ */
        #  define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition)
        #endif
        
        #ifdef __cplusplus
        
        #include <algorithm>
        
        #if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
        
        # define QT_PREPEND_NAMESPACE(name) ::name
        # define QT_USE_NAMESPACE
        # define QT_BEGIN_NAMESPACE
        # define QT_END_NAMESPACE
        # define QT_BEGIN_INCLUDE_NAMESPACE
        # define QT_END_INCLUDE_NAMESPACE
        #ifndef QT_BEGIN_MOC_NAMESPACE
        # define QT_BEGIN_MOC_NAMESPACE
        #endif
        #ifndef QT_END_MOC_NAMESPACE
        # define QT_END_MOC_NAMESPACE
        #endif
        # define QT_FORWARD_DECLARE_CLASS(name) class name;
        # define QT_FORWARD_DECLARE_STRUCT(name) struct name;
        # define QT_MANGLE_NAMESPACE(name) name
        
        #else /* user namespace */
        
        # define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
        # define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
        # define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
        # define QT_END_NAMESPACE }
        # define QT_BEGIN_INCLUDE_NAMESPACE }
        # define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
        #ifndef QT_BEGIN_MOC_NAMESPACE
        # define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
        #endif
        #ifndef QT_END_MOC_NAMESPACE
        # define QT_END_MOC_NAMESPACE
        #endif
        # define QT_FORWARD_DECLARE_CLASS(name) \
            QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
            using QT_PREPEND_NAMESPACE(name);
        
        # define QT_FORWARD_DECLARE_STRUCT(name) \
            QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \
            using QT_PREPEND_NAMESPACE(name);
        
        # define QT_MANGLE_NAMESPACE0(x) x
        # define QT_MANGLE_NAMESPACE1(a, b) a##_##b
        # define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b)
        # define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \
                QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE))
        
        namespace QT_NAMESPACE {}
        
        # ifndef QT_BOOTSTRAPPED
        # ifndef QT_NO_USING_NAMESPACE
           /*
            This expands to a "using QT_NAMESPACE" also in _header files_.
            It is the only way the feature can be used without too much
            pain, but if people _really_ do not want it they can add
            DEFINES += QT_NO_USING_NAMESPACE to their .pro files.
            */
           QT_USE_NAMESPACE
        # endif
        # endif
        
        #endif /* user namespace */
        
        #else /* __cplusplus */
        
        # define QT_BEGIN_NAMESPACE
        # define QT_END_NAMESPACE
        # define QT_USE_NAMESPACE
        # define QT_BEGIN_INCLUDE_NAMESPACE
        # define QT_END_INCLUDE_NAMESPACE
        
        #endif /* __cplusplus */
        
        // ### Qt6: remove me.
        #define QT_BEGIN_HEADER
        #define QT_END_HEADER
        
        #if defined(Q_OS_DARWIN) && !defined(QT_LARGEFILE_SUPPORT)
        #  define QT_LARGEFILE_SUPPORT 64
        #endif
        
        #ifndef __ASSEMBLER__
        QT_BEGIN_NAMESPACE
        
        /*
           Size-dependent types (architechture-dependent byte order)
        
           Make sure to update QMetaType when changing these typedefs
        */
        
        typedef signed char qint8;         /* 8 bit signed */
        typedef unsigned char quint8;      /* 8 bit unsigned */
        typedef short qint16;              /* 16 bit signed */
        typedef unsigned short quint16;    /* 16 bit unsigned */
        typedef int qint32;                /* 32 bit signed */
        typedef unsigned int quint32;      /* 32 bit unsigned */
        #if defined(Q_OS_WIN) && !defined(Q_CC_GNU)
        #  define Q_INT64_C(c) c ## i64    /* signed 64 bit constant */
        #  define Q_UINT64_C(c) c ## ui64   /* unsigned 64 bit constant */
        typedef __int64 qint64;            /* 64 bit signed */
        typedef unsigned __int64 quint64;  /* 64 bit unsigned */
        #else
        #ifdef __cplusplus
        #  define Q_INT64_C(c) static_cast<long long>(c ## LL)     /* signed 64 bit constant */
        #  define Q_UINT64_C(c) static_cast<unsigned long long>(c ## ULL) /* unsigned 64 bit constant */
        #else
        #  define Q_INT64_C(c) ((long long)(c ## LL))               /* signed 64 bit constant */
        #  define Q_UINT64_C(c) ((unsigned long long)(c ## ULL))    /* unsigned 64 bit constant */
        #endif
        typedef long long qint64;           /* 64 bit signed */
        typedef unsigned long long quint64; /* 64 bit unsigned */
        #endif
        
        typedef qint64 qlonglong;
        typedef quint64 qulonglong;
        
        #ifndef __cplusplus
        // In C++ mode, we define below using QIntegerForSize template
        Q_STATIC_ASSERT_X(sizeof(ptrdiff_t) == sizeof(size_t), "Weird ptrdiff_t and size_t definitions");
        typedef ptrdiff_t qptrdiff;
        typedef ptrdiff_t qsizetype;
        typedef ptrdiff_t qintptr;
        typedef size_t quintptr;
        #endif
        
        /*
           Useful type definitions for Qt
        */
        
        QT_BEGIN_INCLUDE_NAMESPACE
        typedef unsigned char uchar;
        typedef unsigned short ushort;
        typedef unsigned int uint;
        typedef unsigned long ulong;
        QT_END_INCLUDE_NAMESPACE
        
        #if defined(QT_COORD_TYPE)
        typedef QT_COORD_TYPE qreal;
        #else
        typedef double qreal;
        #endif
        
        #if defined(QT_NO_DEPRECATED)
        #  undef QT_DEPRECATED
        #  undef QT_DEPRECATED_X
        #  undef QT_DEPRECATED_VARIABLE
        #  undef QT_DEPRECATED_CONSTRUCTOR
        #elif !defined(QT_NO_DEPRECATED_WARNINGS)
        #  undef QT_DEPRECATED
        #  define QT_DEPRECATED Q_DECL_DEPRECATED
        #  undef QT_DEPRECATED_X
        #  define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
        #  undef QT_DEPRECATED_VARIABLE
        #  define QT_DEPRECATED_VARIABLE Q_DECL_VARIABLE_DEPRECATED
        #  undef QT_DEPRECATED_CONSTRUCTOR
        #  define QT_DEPRECATED_CONSTRUCTOR explicit Q_DECL_CONSTRUCTOR_DEPRECATED
        #else
        #  undef QT_DEPRECATED
        #  define QT_DEPRECATED
        #  undef QT_DEPRECATED_X
        #  define QT_DEPRECATED_X(text)
        #  undef QT_DEPRECATED_VARIABLE
        #  define QT_DEPRECATED_VARIABLE
        #  undef QT_DEPRECATED_CONSTRUCTOR
        #  define QT_DEPRECATED_CONSTRUCTOR
        #endif
        
        #ifndef QT_DEPRECATED_WARNINGS_SINCE
        # ifdef QT_DISABLE_DEPRECATED_BEFORE
        #  define QT_DEPRECATED_WARNINGS_SINCE QT_DISABLE_DEPRECATED_BEFORE
        # else
        #  define QT_DEPRECATED_WARNINGS_SINCE QT_VERSION
        # endif
        #endif
        
        #ifndef QT_DISABLE_DEPRECATED_BEFORE
        #define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(5, 0, 0)
        #endif
        
        /*
            QT_DEPRECATED_SINCE(major, minor) evaluates as true if the Qt version is greater than
            the deprecation point specified.
        
            Use it to specify from which version of Qt a function or class has been deprecated
        
            Example:
                #if QT_DEPRECATED_SINCE(5,1)
                    QT_DEPRECATED void deprecatedFunction(); //function deprecated since Qt 5.1
                #endif
        
        */
        #ifdef QT_DEPRECATED
        #define QT_DEPRECATED_SINCE(major, minor) (QT_VERSION_CHECK(major, minor, 0) > QT_DISABLE_DEPRECATED_BEFORE)
        #else
        #define QT_DEPRECATED_SINCE(major, minor) 0
        #endif
        
        /*
          QT_DEPRECATED_VERSION(major, minor) and QT_DEPRECATED_VERSION_X(major, minor, text)
          outputs a deprecation warning if QT_DEPRECATED_WARNINGS_SINCE is equal or greater
          than the version specified as major, minor. This makes it possible to deprecate a
          function without annoying a user who needs to stick at a specified minimum version
          and therefore can't use the new function.
        */
        #if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 12, 0)
        # define QT_DEPRECATED_VERSION_X_5_12(text) QT_DEPRECATED_X(text)
        # define QT_DEPRECATED_VERSION_5_12         QT_DEPRECATED
        #else
        # define QT_DEPRECATED_VERSION_X_5_12(text)
        # define QT_DEPRECATED_VERSION_5_12
        #endif
        
        #if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 13, 0)
        # define QT_DEPRECATED_VERSION_X_5_13(text) QT_DEPRECATED_X(text)
        # define QT_DEPRECATED_VERSION_5_13         QT_DEPRECATED
        #else
        # define QT_DEPRECATED_VERSION_X_5_13(text)
        # define QT_DEPRECATED_VERSION_5_13
        #endif
        
        #if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 14, 0)
        # define QT_DEPRECATED_VERSION_X_5_14(text) QT_DEPRECATED_X(text)
        # define QT_DEPRECATED_VERSION_5_14         QT_DEPRECATED
        #else
        # define QT_DEPRECATED_VERSION_X_5_14(text)
        # define QT_DEPRECATED_VERSION_5_14
        #endif
        
        #if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 15, 0)
        # define QT_DEPRECATED_VERSION_X_5_15(text) QT_DEPRECATED_X(text)
        # define QT_DEPRECATED_VERSION_5_15         QT_DEPRECATED
        #else
        # define QT_DEPRECATED_VERSION_X_5_15(text)
        # define QT_DEPRECATED_VERSION_5_15
        #endif
        
        #define QT_DEPRECATED_VERSION_X_5(minor, text)      QT_DEPRECATED_VERSION_X_5_##minor(text)
        #define QT_DEPRECATED_VERSION_X(major, minor, text) QT_DEPRECATED_VERSION_X_##major(minor, text)
        
        #define QT_DEPRECATED_VERSION_5(minor)      QT_DEPRECATED_VERSION_5_##minor
        #define QT_DEPRECATED_VERSION(major, minor) QT_DEPRECATED_VERSION_##major(minor)
        
        #ifdef __cplusplus
        // A tag to help mark stuff deprecated (cf. QStringViewLiteral)
        namespace QtPrivate {
        enum class Deprecated_t {};
        constexpr Q_DECL_UNUSED Deprecated_t Deprecated = {};
        }
        #endif
        
        /*
           The Qt modules' export macros.
           The options are:
            - defined(QT_STATIC): Qt was built or is being built in static mode
            - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode
           If neither was defined, then QT_SHARED is implied. If Qt was compiled in static
           mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied
           for the bootstrapped tools.
        */
        
        #ifdef QT_BOOTSTRAPPED
        #  ifdef QT_SHARED
        #    error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build"
        #  elif !defined(QT_STATIC)
        #    define QT_STATIC
        #  endif
        #endif
        
        #if defined(QT_SHARED) || !defined(QT_STATIC)
        #  ifdef QT_STATIC
        #    error "Both QT_SHARED and QT_STATIC defined, please make up your mind"
        #  endif
        #  ifndef QT_SHARED
        #    define QT_SHARED
        #  endif
        #  if defined(QT_BUILD_CORE_LIB)
        #    define Q_CORE_EXPORT Q_DECL_EXPORT
        #  else
        #    define Q_CORE_EXPORT Q_DECL_IMPORT
        #  endif
        #else
        #  define Q_CORE_EXPORT
        #endif
        
        /*
           Some classes do not permit copies to be made of an object. These
           classes contains a private copy constructor and assignment
           operator to disable copying (the compiler gives an error message).
        */
        #define Q_DISABLE_COPY(Class) \
            Class(const Class &) = delete;\
            Class &operator=(const Class &) = delete;
        
        #define Q_DISABLE_MOVE(Class) \
            Class(Class &&) = delete; \
            Class &operator=(Class &&) = delete;
        
        #define Q_DISABLE_COPY_MOVE(Class) \
            Q_DISABLE_COPY(Class) \
            Q_DISABLE_MOVE(Class)
        
        /*
           No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
           for Qt's internal unit tests. If you want slower loading times and more
           symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
        */
        #if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED)
        #    define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
        #elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED)
        #    define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
        #else
        #    define Q_AUTOTEST_EXPORT
        #endif
        
        #define Q_INIT_RESOURCE(name) \
            do { extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) ();       \
                QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); } while (false)
        #define Q_CLEANUP_RESOURCE(name) \
            do { extern int QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) ();    \
                QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); } while (false)
        
        /*
         * If we're compiling C++ code:
         *  - and this is a non-namespace build, declare qVersion as extern "C"
         *  - and this is a namespace build, declare it as a regular function
         *    (we're already inside QT_BEGIN_NAMESPACE / QT_END_NAMESPACE)
         * If we're compiling C code, simply declare the function. If Qt was compiled
         * in a namespace, qVersion isn't callable anyway.
         */
        #if !defined(QT_NAMESPACE) && defined(__cplusplus) && !defined(Q_QDOC)
        extern "C"
        #endif
        Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOEXCEPT;
        
        #if defined(__cplusplus)
        
        #ifndef Q_CONSTRUCTOR_FUNCTION
        # define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
            namespace { \
            static const struct AFUNC ## _ctor_class_ { \
                inline AFUNC ## _ctor_class_() { AFUNC(); } \
            } AFUNC ## _ctor_instance_; \
            }
        
        # define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
        #endif
        
        #ifndef Q_DESTRUCTOR_FUNCTION
        # define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
            namespace { \
            static const struct AFUNC ## _dtor_class_ { \
                inline AFUNC ## _dtor_class_() { } \
                inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \
            } AFUNC ## _dtor_instance_; \
            }
        # define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
        #endif
        
        namespace QtPrivate {
            template <class T>
            struct AlignOfHelper
            {
                char c;
                T type;
        
                AlignOfHelper();
                ~AlignOfHelper();
            };
        
            template <class T>
            struct AlignOf_Default
            {
                enum { Value = sizeof(AlignOfHelper<T>) - sizeof(T) };
            };
        
            template <class T> struct AlignOf : AlignOf_Default<T> { };
            template <class T> struct AlignOf<T &> : AlignOf<T> {};
            template <class T> struct AlignOf<T &&> : AlignOf<T> {};
            template <size_t N, class T> struct AlignOf<T[N]> : AlignOf<T> {};
        
        #if defined(Q_PROCESSOR_X86_32) && !defined(Q_OS_WIN)
            template <class T> struct AlignOf_WorkaroundForI386Abi { enum { Value = sizeof(T) }; };
        
            // x86 ABI weirdness
            // Alignment of naked type is 8, but inside struct has alignment 4.
            template <> struct AlignOf<double>  : AlignOf_WorkaroundForI386Abi<double> {};
            template <> struct AlignOf<qint64>  : AlignOf_WorkaroundForI386Abi<qint64> {};
            template <> struct AlignOf<quint64> : AlignOf_WorkaroundForI386Abi<quint64> {};
        #ifdef Q_CC_CLANG
            // GCC and Clang seem to disagree wrt to alignment of arrays
            template <size_t N> struct AlignOf<double[N]>   : AlignOf_Default<double> {};
            template <size_t N> struct AlignOf<qint64[N]>   : AlignOf_Default<qint64> {};
            template <size_t N> struct AlignOf<quint64[N]>  : AlignOf_Default<quint64> {};
        #endif
        #endif
        } // namespace QtPrivate
        
        #define QT_EMULATED_ALIGNOF(T) \
            (size_t(QT_PREPEND_NAMESPACE(QtPrivate)::AlignOf<T>::Value))
        
        #ifndef Q_ALIGNOF
        #define Q_ALIGNOF(T) QT_EMULATED_ALIGNOF(T)
        #endif
        
        
        /*
          quintptr and qptrdiff is guaranteed to be the same size as a pointer, i.e.
        
              sizeof(void *) == sizeof(quintptr)
              && sizeof(void *) == sizeof(qptrdiff)
        
          size_t and qsizetype are not guaranteed to be the same size as a pointer, but
          they usually are.
        */
        template <int> struct QIntegerForSize;
        template <>    struct QIntegerForSize<1> { typedef quint8  Unsigned; typedef qint8  Signed; };
        template <>    struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
        template <>    struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
        template <>    struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
        #if defined(Q_CC_GNU) && defined(__SIZEOF_INT128__)
        template <>    struct QIntegerForSize<16> { __extension__ typedef unsigned __int128 Unsigned; __extension__ typedef __int128 Signed; };
        #endif
        template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
        typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
        typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint;
        typedef QIntegerForSizeof<void*>::Unsigned quintptr;
        typedef QIntegerForSizeof<void*>::Signed qptrdiff;
        typedef qptrdiff qintptr;
        using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
        
        /* moc compats (signals/slots) */
        #ifndef QT_MOC_COMPAT
        #  define QT_MOC_COMPAT
        #else
        #  undef QT_MOC_COMPAT
        #  define QT_MOC_COMPAT
        #endif
        
        #ifdef QT_ASCII_CAST_WARNINGS
        #  define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED_X("Use fromUtf8, QStringLiteral, or QLatin1String")
        #else
        #  define QT_ASCII_CAST_WARN
        #endif
        
        #ifdef Q_PROCESSOR_X86_32
        #  if defined(Q_CC_GNU)
        #    define QT_FASTCALL __attribute__((regparm(3)))
        #  elif defined(Q_CC_MSVC)
        #    define QT_FASTCALL __fastcall
        #  else
        #     define QT_FASTCALL
        #  endif
        #else
        #  define QT_FASTCALL
        #endif
        
        // enable gcc warnings for printf-style functions
        #if defined(Q_CC_GNU) && !defined(__INSURE__)
        #  if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
        #    define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
                 __attribute__((format(gnu_printf, (A), (B))))
        #  else
        #    define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
                 __attribute__((format(printf, (A), (B))))
        #  endif
        #else
        #  define Q_ATTRIBUTE_FORMAT_PRINTF(A, B)
        #endif
        
        #ifdef Q_CC_MSVC
        #  define Q_NEVER_INLINE __declspec(noinline)
        #  define Q_ALWAYS_INLINE __forceinline
        #elif defined(Q_CC_GNU)
        #  define Q_NEVER_INLINE __attribute__((noinline))
        #  define Q_ALWAYS_INLINE inline __attribute__((always_inline))
        #else
        #  define Q_NEVER_INLINE
        #  define Q_ALWAYS_INLINE inline
        #endif
        
        #if defined(Q_CC_GNU) && defined(Q_OS_WIN) && !defined(QT_NO_DATA_RELOCATION)
        // ### Qt6: you can remove me
        
        **#  define QT_INIT_METAOBJECT __attribute__((init_priority(101)))
        #else
        #  define QT_INIT_METAOBJECT
        #endif**
        
        //defines the type for the WNDPROC on windows
        //the alignment needs to be forced for sse2 to not crash with mingw
        #if defined(Q_OS_WIN)
        #  if defined(Q_CC_MINGW) && !defined(Q_OS_WIN64)
        #    define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer))
        #  else
        #    define QT_ENSURE_STACK_ALIGNED_FOR_SSE
        #  endif
        #  define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE
        #endif
        
        

        **# define QT_INIT_METAOBJECT attribute((init_priority(101)))
        #else

        define QT_INIT_METAOBJECT

        #endif**

        Christian EhrlicherC 1 Reply Last reply
        0
        • S Saee1101

          @Christian-Ehrlicher
          qglobal.h :

          /****************************************************************************
          **
          ** Copyright (C) 2019 The Qt Company Ltd.
          ** Copyright (C) 2019 Intel Corporation.
          ** Contact: https://www.qt.io/licensing/
          **
          ** This file is part of the QtCore module of the Qt Toolkit.
          **
          ** $QT_BEGIN_LICENSE:LGPL$
          ** Commercial License Usage
          ** Licensees holding valid commercial Qt licenses may use this file in
          ** accordance with the commercial license agreement provided with the
          ** Software or, alternatively, in accordance with the terms contained in
          ** a written agreement between you and The Qt Company. For licensing terms
          ** and conditions see https://www.qt.io/terms-conditions. For further
          ** information use the contact form at https://www.qt.io/contact-us.
          **
          ** GNU Lesser General Public License Usage
          ** Alternatively, this file may be used under the terms of the GNU Lesser
          ** General Public License version 3 as published by the Free Software
          ** Foundation and appearing in the file LICENSE.LGPL3 included in the
          ** packaging of this file. Please review the following information to
          ** ensure the GNU Lesser General Public License version 3 requirements
          ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
          **
          ** GNU General Public License Usage
          ** Alternatively, this file may be used under the terms of the GNU
          ** General Public License version 2.0 or (at your option) the GNU General
          ** Public license version 3 or any later version approved by the KDE Free
          ** Qt Foundation. The licenses are as published by the Free Software
          ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
          ** included in the packaging of this file. Please review the following
          ** information to ensure the GNU General Public License requirements will
          ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
          ** https://www.gnu.org/licenses/gpl-3.0.html.
          **
          ** $QT_END_LICENSE$
          **
          ****************************************************************************/
          
          #ifndef QGLOBAL_H
          #define QGLOBAL_H
          
          #ifdef __cplusplus
          #  include <type_traits>
          #  include <cstddef>
          #  include <utility>
          #endif
          #ifndef __ASSEMBLER__
          #  include <assert.h>
          #  include <stddef.h>
          #endif
          
          /*
             QT_VERSION is (major << 16) + (minor << 8) + patch.
          */
          #define QT_VERSION      QT_VERSION_CHECK(QT_VERSION_MAJOR, QT_VERSION_MINOR, QT_VERSION_PATCH)
          /*
             can be used like #if (QT_VERSION >= QT_VERSION_CHECK(4, 4, 0))
          */
          #define QT_VERSION_CHECK(major, minor, patch) ((major<<16)|(minor<<8)|(patch))
          
          #ifdef QT_BOOTSTRAPPED
          #include <QtCore/qconfig-bootstrapped.h>
          #else
          #include <QtCore/qconfig.h>
          #include <QtCore/qtcore-config.h>
          #endif
          
          // The QT_SUPPORTS macro is deprecated. Don't use it in new code.
          // Instead, use QT_CONFIG(feature)
          // ### Qt6: remove macro
          #ifdef _MSC_VER
          #  define QT_SUPPORTS(FEATURE) (!defined QT_NO_##FEATURE)
          #else
          #  define QT_SUPPORTS(FEATURE) (!defined(QT_NO_##FEATURE))
          #endif
          
          /*
              The QT_CONFIG macro implements a safe compile time check for features of Qt.
              Features can be in three states:
                  0 or undefined: This will lead to a compile error when testing for it
                  -1: The feature is not available
                  1: The feature is available
          */
          #define QT_CONFIG(feature) (1/QT_FEATURE_##feature == 1)
          #define QT_REQUIRE_CONFIG(feature) Q_STATIC_ASSERT_X(QT_FEATURE_##feature == 1, "Required feature " #feature " for file " __FILE__ " not available.")
          
          #if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
          #  define QT_NO_UNSHARABLE_CONTAINERS
          #  define QT6_VIRTUAL virtual
          #  define QT6_NOT_VIRTUAL
          #else
          #  define QT6_VIRTUAL
          #  define QT6_NOT_VIRTUAL virtual
          #endif
          
          /* These two macros makes it possible to turn the builtin line expander into a
           * string literal. */
          #define QT_STRINGIFY2(x) #x
          #define QT_STRINGIFY(x) QT_STRINGIFY2(x)
          
          #include <QtCore/qsystemdetection.h>
          #include <QtCore/qprocessordetection.h>
          #include <QtCore/qcompilerdetection.h>
          
          #if defined (__ELF__)
          #  define Q_OF_ELF
          #endif
          #if defined (__MACH__) && defined (__APPLE__)
          #  define Q_OF_MACH_O
          #endif
          
          /*
             Avoid "unused parameter" warnings
          */
          #define Q_UNUSED(x) (void)x;
          
          #if defined(__cplusplus) && defined(Q_COMPILER_STATIC_ASSERT)
          #  define Q_STATIC_ASSERT(Condition) static_assert(bool(Condition), #Condition)
          #  define Q_STATIC_ASSERT_X(Condition, Message) static_assert(bool(Condition), Message)
          #elif defined(Q_COMPILER_STATIC_ASSERT)
          // C11 mode - using the _S version in case <assert.h> doesn't do the right thing
          #  define Q_STATIC_ASSERT(Condition) _Static_assert(!!(Condition), #Condition)
          #  define Q_STATIC_ASSERT_X(Condition, Message) _Static_assert(!!(Condition), Message)
          #else
          // C89 & C99 version
          #  define Q_STATIC_ASSERT_PRIVATE_JOIN(A, B) Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B)
          #  define Q_STATIC_ASSERT_PRIVATE_JOIN_IMPL(A, B) A ## B
          #  ifdef __COUNTER__
          #  define Q_STATIC_ASSERT(Condition) \
              typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __COUNTER__) [(Condition) ? 1 : -1];
          #  else
          #  define Q_STATIC_ASSERT(Condition) \
              typedef char Q_STATIC_ASSERT_PRIVATE_JOIN(q_static_assert_result, __LINE__) [(Condition) ? 1 : -1];
          #  endif /* __COUNTER__ */
          #  define Q_STATIC_ASSERT_X(Condition, Message) Q_STATIC_ASSERT(Condition)
          #endif
          
          #ifdef __cplusplus
          
          #include <algorithm>
          
          #if !defined(QT_NAMESPACE) || defined(Q_MOC_RUN) /* user namespace */
          
          # define QT_PREPEND_NAMESPACE(name) ::name
          # define QT_USE_NAMESPACE
          # define QT_BEGIN_NAMESPACE
          # define QT_END_NAMESPACE
          # define QT_BEGIN_INCLUDE_NAMESPACE
          # define QT_END_INCLUDE_NAMESPACE
          #ifndef QT_BEGIN_MOC_NAMESPACE
          # define QT_BEGIN_MOC_NAMESPACE
          #endif
          #ifndef QT_END_MOC_NAMESPACE
          # define QT_END_MOC_NAMESPACE
          #endif
          # define QT_FORWARD_DECLARE_CLASS(name) class name;
          # define QT_FORWARD_DECLARE_STRUCT(name) struct name;
          # define QT_MANGLE_NAMESPACE(name) name
          
          #else /* user namespace */
          
          # define QT_PREPEND_NAMESPACE(name) ::QT_NAMESPACE::name
          # define QT_USE_NAMESPACE using namespace ::QT_NAMESPACE;
          # define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE {
          # define QT_END_NAMESPACE }
          # define QT_BEGIN_INCLUDE_NAMESPACE }
          # define QT_END_INCLUDE_NAMESPACE namespace QT_NAMESPACE {
          #ifndef QT_BEGIN_MOC_NAMESPACE
          # define QT_BEGIN_MOC_NAMESPACE QT_USE_NAMESPACE
          #endif
          #ifndef QT_END_MOC_NAMESPACE
          # define QT_END_MOC_NAMESPACE
          #endif
          # define QT_FORWARD_DECLARE_CLASS(name) \
              QT_BEGIN_NAMESPACE class name; QT_END_NAMESPACE \
              using QT_PREPEND_NAMESPACE(name);
          
          # define QT_FORWARD_DECLARE_STRUCT(name) \
              QT_BEGIN_NAMESPACE struct name; QT_END_NAMESPACE \
              using QT_PREPEND_NAMESPACE(name);
          
          # define QT_MANGLE_NAMESPACE0(x) x
          # define QT_MANGLE_NAMESPACE1(a, b) a##_##b
          # define QT_MANGLE_NAMESPACE2(a, b) QT_MANGLE_NAMESPACE1(a,b)
          # define QT_MANGLE_NAMESPACE(name) QT_MANGLE_NAMESPACE2( \
                  QT_MANGLE_NAMESPACE0(name), QT_MANGLE_NAMESPACE0(QT_NAMESPACE))
          
          namespace QT_NAMESPACE {}
          
          # ifndef QT_BOOTSTRAPPED
          # ifndef QT_NO_USING_NAMESPACE
             /*
              This expands to a "using QT_NAMESPACE" also in _header files_.
              It is the only way the feature can be used without too much
              pain, but if people _really_ do not want it they can add
              DEFINES += QT_NO_USING_NAMESPACE to their .pro files.
              */
             QT_USE_NAMESPACE
          # endif
          # endif
          
          #endif /* user namespace */
          
          #else /* __cplusplus */
          
          # define QT_BEGIN_NAMESPACE
          # define QT_END_NAMESPACE
          # define QT_USE_NAMESPACE
          # define QT_BEGIN_INCLUDE_NAMESPACE
          # define QT_END_INCLUDE_NAMESPACE
          
          #endif /* __cplusplus */
          
          // ### Qt6: remove me.
          #define QT_BEGIN_HEADER
          #define QT_END_HEADER
          
          #if defined(Q_OS_DARWIN) && !defined(QT_LARGEFILE_SUPPORT)
          #  define QT_LARGEFILE_SUPPORT 64
          #endif
          
          #ifndef __ASSEMBLER__
          QT_BEGIN_NAMESPACE
          
          /*
             Size-dependent types (architechture-dependent byte order)
          
             Make sure to update QMetaType when changing these typedefs
          */
          
          typedef signed char qint8;         /* 8 bit signed */
          typedef unsigned char quint8;      /* 8 bit unsigned */
          typedef short qint16;              /* 16 bit signed */
          typedef unsigned short quint16;    /* 16 bit unsigned */
          typedef int qint32;                /* 32 bit signed */
          typedef unsigned int quint32;      /* 32 bit unsigned */
          #if defined(Q_OS_WIN) && !defined(Q_CC_GNU)
          #  define Q_INT64_C(c) c ## i64    /* signed 64 bit constant */
          #  define Q_UINT64_C(c) c ## ui64   /* unsigned 64 bit constant */
          typedef __int64 qint64;            /* 64 bit signed */
          typedef unsigned __int64 quint64;  /* 64 bit unsigned */
          #else
          #ifdef __cplusplus
          #  define Q_INT64_C(c) static_cast<long long>(c ## LL)     /* signed 64 bit constant */
          #  define Q_UINT64_C(c) static_cast<unsigned long long>(c ## ULL) /* unsigned 64 bit constant */
          #else
          #  define Q_INT64_C(c) ((long long)(c ## LL))               /* signed 64 bit constant */
          #  define Q_UINT64_C(c) ((unsigned long long)(c ## ULL))    /* unsigned 64 bit constant */
          #endif
          typedef long long qint64;           /* 64 bit signed */
          typedef unsigned long long quint64; /* 64 bit unsigned */
          #endif
          
          typedef qint64 qlonglong;
          typedef quint64 qulonglong;
          
          #ifndef __cplusplus
          // In C++ mode, we define below using QIntegerForSize template
          Q_STATIC_ASSERT_X(sizeof(ptrdiff_t) == sizeof(size_t), "Weird ptrdiff_t and size_t definitions");
          typedef ptrdiff_t qptrdiff;
          typedef ptrdiff_t qsizetype;
          typedef ptrdiff_t qintptr;
          typedef size_t quintptr;
          #endif
          
          /*
             Useful type definitions for Qt
          */
          
          QT_BEGIN_INCLUDE_NAMESPACE
          typedef unsigned char uchar;
          typedef unsigned short ushort;
          typedef unsigned int uint;
          typedef unsigned long ulong;
          QT_END_INCLUDE_NAMESPACE
          
          #if defined(QT_COORD_TYPE)
          typedef QT_COORD_TYPE qreal;
          #else
          typedef double qreal;
          #endif
          
          #if defined(QT_NO_DEPRECATED)
          #  undef QT_DEPRECATED
          #  undef QT_DEPRECATED_X
          #  undef QT_DEPRECATED_VARIABLE
          #  undef QT_DEPRECATED_CONSTRUCTOR
          #elif !defined(QT_NO_DEPRECATED_WARNINGS)
          #  undef QT_DEPRECATED
          #  define QT_DEPRECATED Q_DECL_DEPRECATED
          #  undef QT_DEPRECATED_X
          #  define QT_DEPRECATED_X(text) Q_DECL_DEPRECATED_X(text)
          #  undef QT_DEPRECATED_VARIABLE
          #  define QT_DEPRECATED_VARIABLE Q_DECL_VARIABLE_DEPRECATED
          #  undef QT_DEPRECATED_CONSTRUCTOR
          #  define QT_DEPRECATED_CONSTRUCTOR explicit Q_DECL_CONSTRUCTOR_DEPRECATED
          #else
          #  undef QT_DEPRECATED
          #  define QT_DEPRECATED
          #  undef QT_DEPRECATED_X
          #  define QT_DEPRECATED_X(text)
          #  undef QT_DEPRECATED_VARIABLE
          #  define QT_DEPRECATED_VARIABLE
          #  undef QT_DEPRECATED_CONSTRUCTOR
          #  define QT_DEPRECATED_CONSTRUCTOR
          #endif
          
          #ifndef QT_DEPRECATED_WARNINGS_SINCE
          # ifdef QT_DISABLE_DEPRECATED_BEFORE
          #  define QT_DEPRECATED_WARNINGS_SINCE QT_DISABLE_DEPRECATED_BEFORE
          # else
          #  define QT_DEPRECATED_WARNINGS_SINCE QT_VERSION
          # endif
          #endif
          
          #ifndef QT_DISABLE_DEPRECATED_BEFORE
          #define QT_DISABLE_DEPRECATED_BEFORE QT_VERSION_CHECK(5, 0, 0)
          #endif
          
          /*
              QT_DEPRECATED_SINCE(major, minor) evaluates as true if the Qt version is greater than
              the deprecation point specified.
          
              Use it to specify from which version of Qt a function or class has been deprecated
          
              Example:
                  #if QT_DEPRECATED_SINCE(5,1)
                      QT_DEPRECATED void deprecatedFunction(); //function deprecated since Qt 5.1
                  #endif
          
          */
          #ifdef QT_DEPRECATED
          #define QT_DEPRECATED_SINCE(major, minor) (QT_VERSION_CHECK(major, minor, 0) > QT_DISABLE_DEPRECATED_BEFORE)
          #else
          #define QT_DEPRECATED_SINCE(major, minor) 0
          #endif
          
          /*
            QT_DEPRECATED_VERSION(major, minor) and QT_DEPRECATED_VERSION_X(major, minor, text)
            outputs a deprecation warning if QT_DEPRECATED_WARNINGS_SINCE is equal or greater
            than the version specified as major, minor. This makes it possible to deprecate a
            function without annoying a user who needs to stick at a specified minimum version
            and therefore can't use the new function.
          */
          #if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 12, 0)
          # define QT_DEPRECATED_VERSION_X_5_12(text) QT_DEPRECATED_X(text)
          # define QT_DEPRECATED_VERSION_5_12         QT_DEPRECATED
          #else
          # define QT_DEPRECATED_VERSION_X_5_12(text)
          # define QT_DEPRECATED_VERSION_5_12
          #endif
          
          #if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 13, 0)
          # define QT_DEPRECATED_VERSION_X_5_13(text) QT_DEPRECATED_X(text)
          # define QT_DEPRECATED_VERSION_5_13         QT_DEPRECATED
          #else
          # define QT_DEPRECATED_VERSION_X_5_13(text)
          # define QT_DEPRECATED_VERSION_5_13
          #endif
          
          #if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 14, 0)
          # define QT_DEPRECATED_VERSION_X_5_14(text) QT_DEPRECATED_X(text)
          # define QT_DEPRECATED_VERSION_5_14         QT_DEPRECATED
          #else
          # define QT_DEPRECATED_VERSION_X_5_14(text)
          # define QT_DEPRECATED_VERSION_5_14
          #endif
          
          #if QT_DEPRECATED_WARNINGS_SINCE >= QT_VERSION_CHECK(5, 15, 0)
          # define QT_DEPRECATED_VERSION_X_5_15(text) QT_DEPRECATED_X(text)
          # define QT_DEPRECATED_VERSION_5_15         QT_DEPRECATED
          #else
          # define QT_DEPRECATED_VERSION_X_5_15(text)
          # define QT_DEPRECATED_VERSION_5_15
          #endif
          
          #define QT_DEPRECATED_VERSION_X_5(minor, text)      QT_DEPRECATED_VERSION_X_5_##minor(text)
          #define QT_DEPRECATED_VERSION_X(major, minor, text) QT_DEPRECATED_VERSION_X_##major(minor, text)
          
          #define QT_DEPRECATED_VERSION_5(minor)      QT_DEPRECATED_VERSION_5_##minor
          #define QT_DEPRECATED_VERSION(major, minor) QT_DEPRECATED_VERSION_##major(minor)
          
          #ifdef __cplusplus
          // A tag to help mark stuff deprecated (cf. QStringViewLiteral)
          namespace QtPrivate {
          enum class Deprecated_t {};
          constexpr Q_DECL_UNUSED Deprecated_t Deprecated = {};
          }
          #endif
          
          /*
             The Qt modules' export macros.
             The options are:
              - defined(QT_STATIC): Qt was built or is being built in static mode
              - defined(QT_SHARED): Qt was built or is being built in shared/dynamic mode
             If neither was defined, then QT_SHARED is implied. If Qt was compiled in static
             mode, QT_STATIC is defined in qconfig.h. In shared mode, QT_STATIC is implied
             for the bootstrapped tools.
          */
          
          #ifdef QT_BOOTSTRAPPED
          #  ifdef QT_SHARED
          #    error "QT_SHARED and QT_BOOTSTRAPPED together don't make sense. Please fix the build"
          #  elif !defined(QT_STATIC)
          #    define QT_STATIC
          #  endif
          #endif
          
          #if defined(QT_SHARED) || !defined(QT_STATIC)
          #  ifdef QT_STATIC
          #    error "Both QT_SHARED and QT_STATIC defined, please make up your mind"
          #  endif
          #  ifndef QT_SHARED
          #    define QT_SHARED
          #  endif
          #  if defined(QT_BUILD_CORE_LIB)
          #    define Q_CORE_EXPORT Q_DECL_EXPORT
          #  else
          #    define Q_CORE_EXPORT Q_DECL_IMPORT
          #  endif
          #else
          #  define Q_CORE_EXPORT
          #endif
          
          /*
             Some classes do not permit copies to be made of an object. These
             classes contains a private copy constructor and assignment
             operator to disable copying (the compiler gives an error message).
          */
          #define Q_DISABLE_COPY(Class) \
              Class(const Class &) = delete;\
              Class &operator=(const Class &) = delete;
          
          #define Q_DISABLE_MOVE(Class) \
              Class(Class &&) = delete; \
              Class &operator=(Class &&) = delete;
          
          #define Q_DISABLE_COPY_MOVE(Class) \
              Q_DISABLE_COPY(Class) \
              Q_DISABLE_MOVE(Class)
          
          /*
             No, this is not an evil backdoor. QT_BUILD_INTERNAL just exports more symbols
             for Qt's internal unit tests. If you want slower loading times and more
             symbols that can vanish from version to version, feel free to define QT_BUILD_INTERNAL.
          */
          #if defined(QT_BUILD_INTERNAL) && defined(QT_BUILDING_QT) && defined(QT_SHARED)
          #    define Q_AUTOTEST_EXPORT Q_DECL_EXPORT
          #elif defined(QT_BUILD_INTERNAL) && defined(QT_SHARED)
          #    define Q_AUTOTEST_EXPORT Q_DECL_IMPORT
          #else
          #    define Q_AUTOTEST_EXPORT
          #endif
          
          #define Q_INIT_RESOURCE(name) \
              do { extern int QT_MANGLE_NAMESPACE(qInitResources_ ## name) ();       \
                  QT_MANGLE_NAMESPACE(qInitResources_ ## name) (); } while (false)
          #define Q_CLEANUP_RESOURCE(name) \
              do { extern int QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) ();    \
                  QT_MANGLE_NAMESPACE(qCleanupResources_ ## name) (); } while (false)
          
          /*
           * If we're compiling C++ code:
           *  - and this is a non-namespace build, declare qVersion as extern "C"
           *  - and this is a namespace build, declare it as a regular function
           *    (we're already inside QT_BEGIN_NAMESPACE / QT_END_NAMESPACE)
           * If we're compiling C code, simply declare the function. If Qt was compiled
           * in a namespace, qVersion isn't callable anyway.
           */
          #if !defined(QT_NAMESPACE) && defined(__cplusplus) && !defined(Q_QDOC)
          extern "C"
          #endif
          Q_CORE_EXPORT Q_DECL_CONST_FUNCTION const char *qVersion(void) Q_DECL_NOEXCEPT;
          
          #if defined(__cplusplus)
          
          #ifndef Q_CONSTRUCTOR_FUNCTION
          # define Q_CONSTRUCTOR_FUNCTION0(AFUNC) \
              namespace { \
              static const struct AFUNC ## _ctor_class_ { \
                  inline AFUNC ## _ctor_class_() { AFUNC(); } \
              } AFUNC ## _ctor_instance_; \
              }
          
          # define Q_CONSTRUCTOR_FUNCTION(AFUNC) Q_CONSTRUCTOR_FUNCTION0(AFUNC)
          #endif
          
          #ifndef Q_DESTRUCTOR_FUNCTION
          # define Q_DESTRUCTOR_FUNCTION0(AFUNC) \
              namespace { \
              static const struct AFUNC ## _dtor_class_ { \
                  inline AFUNC ## _dtor_class_() { } \
                  inline ~ AFUNC ## _dtor_class_() { AFUNC(); } \
              } AFUNC ## _dtor_instance_; \
              }
          # define Q_DESTRUCTOR_FUNCTION(AFUNC) Q_DESTRUCTOR_FUNCTION0(AFUNC)
          #endif
          
          namespace QtPrivate {
              template <class T>
              struct AlignOfHelper
              {
                  char c;
                  T type;
          
                  AlignOfHelper();
                  ~AlignOfHelper();
              };
          
              template <class T>
              struct AlignOf_Default
              {
                  enum { Value = sizeof(AlignOfHelper<T>) - sizeof(T) };
              };
          
              template <class T> struct AlignOf : AlignOf_Default<T> { };
              template <class T> struct AlignOf<T &> : AlignOf<T> {};
              template <class T> struct AlignOf<T &&> : AlignOf<T> {};
              template <size_t N, class T> struct AlignOf<T[N]> : AlignOf<T> {};
          
          #if defined(Q_PROCESSOR_X86_32) && !defined(Q_OS_WIN)
              template <class T> struct AlignOf_WorkaroundForI386Abi { enum { Value = sizeof(T) }; };
          
              // x86 ABI weirdness
              // Alignment of naked type is 8, but inside struct has alignment 4.
              template <> struct AlignOf<double>  : AlignOf_WorkaroundForI386Abi<double> {};
              template <> struct AlignOf<qint64>  : AlignOf_WorkaroundForI386Abi<qint64> {};
              template <> struct AlignOf<quint64> : AlignOf_WorkaroundForI386Abi<quint64> {};
          #ifdef Q_CC_CLANG
              // GCC and Clang seem to disagree wrt to alignment of arrays
              template <size_t N> struct AlignOf<double[N]>   : AlignOf_Default<double> {};
              template <size_t N> struct AlignOf<qint64[N]>   : AlignOf_Default<qint64> {};
              template <size_t N> struct AlignOf<quint64[N]>  : AlignOf_Default<quint64> {};
          #endif
          #endif
          } // namespace QtPrivate
          
          #define QT_EMULATED_ALIGNOF(T) \
              (size_t(QT_PREPEND_NAMESPACE(QtPrivate)::AlignOf<T>::Value))
          
          #ifndef Q_ALIGNOF
          #define Q_ALIGNOF(T) QT_EMULATED_ALIGNOF(T)
          #endif
          
          
          /*
            quintptr and qptrdiff is guaranteed to be the same size as a pointer, i.e.
          
                sizeof(void *) == sizeof(quintptr)
                && sizeof(void *) == sizeof(qptrdiff)
          
            size_t and qsizetype are not guaranteed to be the same size as a pointer, but
            they usually are.
          */
          template <int> struct QIntegerForSize;
          template <>    struct QIntegerForSize<1> { typedef quint8  Unsigned; typedef qint8  Signed; };
          template <>    struct QIntegerForSize<2> { typedef quint16 Unsigned; typedef qint16 Signed; };
          template <>    struct QIntegerForSize<4> { typedef quint32 Unsigned; typedef qint32 Signed; };
          template <>    struct QIntegerForSize<8> { typedef quint64 Unsigned; typedef qint64 Signed; };
          #if defined(Q_CC_GNU) && defined(__SIZEOF_INT128__)
          template <>    struct QIntegerForSize<16> { __extension__ typedef unsigned __int128 Unsigned; __extension__ typedef __int128 Signed; };
          #endif
          template <class T> struct QIntegerForSizeof: QIntegerForSize<sizeof(T)> { };
          typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Signed qregisterint;
          typedef QIntegerForSize<Q_PROCESSOR_WORDSIZE>::Unsigned qregisteruint;
          typedef QIntegerForSizeof<void*>::Unsigned quintptr;
          typedef QIntegerForSizeof<void*>::Signed qptrdiff;
          typedef qptrdiff qintptr;
          using qsizetype = QIntegerForSizeof<std::size_t>::Signed;
          
          /* moc compats (signals/slots) */
          #ifndef QT_MOC_COMPAT
          #  define QT_MOC_COMPAT
          #else
          #  undef QT_MOC_COMPAT
          #  define QT_MOC_COMPAT
          #endif
          
          #ifdef QT_ASCII_CAST_WARNINGS
          #  define QT_ASCII_CAST_WARN Q_DECL_DEPRECATED_X("Use fromUtf8, QStringLiteral, or QLatin1String")
          #else
          #  define QT_ASCII_CAST_WARN
          #endif
          
          #ifdef Q_PROCESSOR_X86_32
          #  if defined(Q_CC_GNU)
          #    define QT_FASTCALL __attribute__((regparm(3)))
          #  elif defined(Q_CC_MSVC)
          #    define QT_FASTCALL __fastcall
          #  else
          #     define QT_FASTCALL
          #  endif
          #else
          #  define QT_FASTCALL
          #endif
          
          // enable gcc warnings for printf-style functions
          #if defined(Q_CC_GNU) && !defined(__INSURE__)
          #  if defined(Q_CC_MINGW) && !defined(Q_CC_CLANG)
          #    define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
                   __attribute__((format(gnu_printf, (A), (B))))
          #  else
          #    define Q_ATTRIBUTE_FORMAT_PRINTF(A, B) \
                   __attribute__((format(printf, (A), (B))))
          #  endif
          #else
          #  define Q_ATTRIBUTE_FORMAT_PRINTF(A, B)
          #endif
          
          #ifdef Q_CC_MSVC
          #  define Q_NEVER_INLINE __declspec(noinline)
          #  define Q_ALWAYS_INLINE __forceinline
          #elif defined(Q_CC_GNU)
          #  define Q_NEVER_INLINE __attribute__((noinline))
          #  define Q_ALWAYS_INLINE inline __attribute__((always_inline))
          #else
          #  define Q_NEVER_INLINE
          #  define Q_ALWAYS_INLINE inline
          #endif
          
          #if defined(Q_CC_GNU) && defined(Q_OS_WIN) && !defined(QT_NO_DATA_RELOCATION)
          // ### Qt6: you can remove me
          
          **#  define QT_INIT_METAOBJECT __attribute__((init_priority(101)))
          #else
          #  define QT_INIT_METAOBJECT
          #endif**
          
          //defines the type for the WNDPROC on windows
          //the alignment needs to be forced for sse2 to not crash with mingw
          #if defined(Q_OS_WIN)
          #  if defined(Q_CC_MINGW) && !defined(Q_OS_WIN64)
          #    define QT_ENSURE_STACK_ALIGNED_FOR_SSE __attribute__ ((force_align_arg_pointer))
          #  else
          #    define QT_ENSURE_STACK_ALIGNED_FOR_SSE
          #  endif
          #  define QT_WIN_CALLBACK CALLBACK QT_ENSURE_STACK_ALIGNED_FOR_SSE
          #endif
          
          

          **# define QT_INIT_METAOBJECT attribute((init_priority(101)))
          #else

          define QT_INIT_METAOBJECT

          #endif**

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Why do you post qglobal.h? You should post your code which triggers this error.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          S 1 Reply Last reply
          0
          • Christian EhrlicherC Christian Ehrlicher

            Why do you post qglobal.h? You should post your code which triggers this error.

            S Offline
            S Offline
            Saee1101
            wrote on last edited by
            #5

            mainwindow.cpp :

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            
            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            
            void MainWindow::on_pushButton_clicked()
            {
                SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
            
                   // We need to set the username (your email address) and the password
                   // for smtp authentification.
            
            //       smtp.setUser("your_email_address@gmail.com");
            //       smtp.setPassword("your_password");
            
                   // Now we create a MimeMessage object. This will be the email.
            
                   MimeMessage message;
            
            //       message.setSender(new EmailAddress("your_email_address@gmail.com", "Your Name"));
            //       message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name"));
                   message.setSubject("SmtpClient for Qt - Demo");
            
                   // Now add some text to the email.
                   // First we create a MimeText object.
            
                   MimeText text;
            
                   text.setText("Hi,\nThis is a simple email message.\n");
            
                   // Now add it to the mail
            
                   message.addPart(&text);
            
                   // Now we can send the mail
            
                   smtp.connectToHost();
            //       smtp.login();
                   smtp.sendMail(message);
                   smtp.quit();
            
               }
            
            Christian EhrlicherC 1 Reply Last reply
            0
            • S Saee1101

              mainwindow.cpp :

              #include "mainwindow.h"
              #include "ui_mainwindow.h"
              
              MainWindow::MainWindow(QWidget *parent)
                  : QMainWindow(parent)
                  , ui(new Ui::MainWindow)
              {
                  ui->setupUi(this);
              }
              
              MainWindow::~MainWindow()
              {
                  delete ui;
              }
              
              
              void MainWindow::on_pushButton_clicked()
              {
                  SmtpClient smtp("smtp.gmail.com", 465, SmtpClient::SslConnection);
              
                     // We need to set the username (your email address) and the password
                     // for smtp authentification.
              
              //       smtp.setUser("your_email_address@gmail.com");
              //       smtp.setPassword("your_password");
              
                     // Now we create a MimeMessage object. This will be the email.
              
                     MimeMessage message;
              
              //       message.setSender(new EmailAddress("your_email_address@gmail.com", "Your Name"));
              //       message.addRecipient(new EmailAddress("recipient@host.com", "Recipient's Name"));
                     message.setSubject("SmtpClient for Qt - Demo");
              
                     // Now add some text to the email.
                     // First we create a MimeText object.
              
                     MimeText text;
              
                     text.setText("Hi,\nThis is a simple email message.\n");
              
                     // Now add it to the mail
              
                     message.addPart(&text);
              
                     // Now we can send the mail
              
                     smtp.connectToHost();
              //       smtp.login();
                     smtp.sendMail(message);
                     smtp.quit();
              
                 }
              
              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @Saee1101 said in C2491: 'SmtpClient::staticMetaObject': definition of dllimport static data member not allowed:

              SmtpClient

              Where comes this class from? As I already said the export macro is wrong for this class.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              S 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @Saee1101 said in C2491: 'SmtpClient::staticMetaObject': definition of dllimport static data member not allowed:

                SmtpClient

                Where comes this class from? As I already said the export macro is wrong for this class.

                S Offline
                S Offline
                Saee1101
                wrote on last edited by Saee1101
                #7

                smtpclient.h :

                
                  Copyright (c) 2011-2012 - Tőkés Attila
                
                  This file is part of SmtpClient for Qt.
                
                  This library is free software; you can redistribute it and/or
                  modify it under the terms of the GNU Lesser General Public
                  License as published by the Free Software Foundation; either
                  version 2.1 of the License, or (at your option) any later version.
                
                  This library is distributed in the hope that it will be useful,
                  but WITHOUT ANY WARRANTY; without even the implied warranty of
                  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                  Lesser General Public License for more details.
                
                  See the LICENSE file for more details.
                */
                
                #ifndef SMTPCLIENT_H
                #define SMTPCLIENT_H
                
                #include <QObject>
                #include <QtNetwork/QSslSocket>
                #include <QEventLoop>
                #include "smtpmime_global.h"
                #include "mimemessage.h"
                
                
                class SMTP_MIME_EXPORT SmtpClient : public QObject
                {
                    Q_OBJECT
                    Q_ENUMS (AuthMethod SmtpError ConnectionType ClientState)
                public:
                
                    /* [0] Enumerations */
                
                    enum AuthMethod
                    {
                        AuthPlain,
                        AuthLogin
                    };
                
                    enum SmtpError
                    {
                        ConnectionTimeoutError = 0,
                        ResponseTimeoutError = 1,
                        AuthenticationError = 2,
                        MailSendingError = 3,
                        ServerError = 4,    // 4xx smtp error
                        ClientError = 5,    // 5xx smtp error
                        SocketError = 6
                    };
                
                    enum ConnectionType
                    {
                        TcpConnection = 0,
                        SslConnection = 1,
                        TlsConnection = 2      // STARTTLS
                    };
                
                    enum ClientState {
                        UnconnectedState = 0,
                        ConnectingState = 1,
                        ConnectedState = 2,
                        ReadyState = 3,
                        AuthenticatingState = 4,
                        MailSendingState = 5,
                        DisconnectingState = 6,
                        ResetState = 7,
                
                        /* Internal States */
                        _EHLO_State = 50,
                        _TLS_State = 51,
                
                        _READY_Connected = 52,
                        _READY_Authenticated = 53,
                        _READY_MailSent = 54,
                        _READY_Encrypted = 55,
                
                        _QUITTING_State = 56,
                
                        /* Internal Substates */
                
                        // TLS
                        _TLS_0_STARTTLS = 60,
                        _TLS_1_ENCRYPT = 61,
                        _TLS_2_EHLO = 62,
                
                        // AUTH
                        _AUTH_PLAIN_0 = 70,
                        _AUTH_LOGIN_0 = 71,
                        _AUTH_LOGIN_1_USER = 72,
                        _AUTH_LOGIN_2_PASS = 73,
                
                        // MAIL
                        _MAIL_0_FROM = 81,
                        _MAIL_1_RCPT_INIT = 82,
                        _MAIL_2_RCPT = 83,
                        _MAIL_3_DATA = 84,
                        _MAIL_4_SEND_DATA = 85
                    };
                
                    /* [0] --- */
                
                
                    /* [1] Constructors and Destructors */
                
                    SmtpClient(const QString & host = "localhost", int port = 25, ConnectionType ct = TcpConnection);
                
                    ~SmtpClient();
                
                    /* [1] --- */
                
                
                    /* [2] Getters and Setters */
                
                    QString getHost() const;
                    int getPort() const;
                    ConnectionType getConnectionType() const;
                
                    QString getName() const;
                    void setName(const QString &name);
                
                    QString getResponseText() const;
                    int getResponseCode() const;
                
                    QTcpSocket* getSocket();
                
                    /* [2] --- */
                
                
                    /* [3] Public methods */
                
                    void connectToHost();
                    void login(const QString &user, const QString &password, AuthMethod method = AuthLogin);
                    void sendMail(const MimeMessage & email);
                    void quit();
                    void reset();
                
                    bool waitForReadyConnected(int msec = 30000);
                    bool waitForAuthenticated(int msec = 30000);
                    bool waitForMailSent(int msec = 30000);
                    bool waitForReset(int msec = 30000);
                
                    bool waitForDisconnected(int msec = 30000);
                
                    /* [3] --- */
                
                protected:
                
                    /* [4] Protected members */
                
                    struct AuthInfo {
                        QString username;
                        QString password;
                        AuthMethod authMethod;
                
                        AuthInfo(const QString & username = "", const QString &password = "", AuthMethod authMethod = AuthPlain) :
                            username(username), password(password), authMethod(authMethod) {}
                    };
                
                    QTcpSocket *socket;
                    ClientState state;
                
                    const QString host;
                    const int port;
                    ConnectionType connectionType;
                
                    QString name;
                
                    AuthInfo authInfo;
                
                    QString responseText;
                    QString tempResponse;
                    int responseCode;
                
                    bool isReadyConnected;
                    bool isAuthenticated;
                    bool isMailSent;
                    bool isReset;
                
                    const MimeMessage *email;
                
                    int rcptType;
                    enum _RcptType { _TO = 1, _CC = 2, _BCC = 3};
                
                    QList<EmailAddress>::const_iterator addressIt;
                    QList<EmailAddress>::const_iterator addressItEnd;
                
                    /* [4] --- */
                
                
                    /* [5] Protected methods */
                    void login();
                    void setConnectionType(ConnectionType ct);
                    void changeState(ClientState state);
                    void processResponse();
                    void sendMessage(const QString &text);
                    void emitError(SmtpClient::SmtpError e);
                    void waitForEvent(int msec, const char *successSignal);
                
                    /* [5] --- */
                
                protected slots:
                
                    /* [6] Protected slots */
                
                    void socketStateChanged(QAbstractSocket::SocketState state);
                    void socketError(QAbstractSocket::SocketError error);
                    void socketReadyRead();
                    void socketEncrypted();
                
                    /* [6] --- */
                
                
                signals:
                
                    /* [7] Signals */
                
                    void error(SmtpClient::SmtpError e);
                    void stateChanged(SmtpClient::ClientState s);
                    void connected();
                    void readyConnected();
                    void authenticated();
                    void mailSent();
                    void mailReset();
                    void disconnected();
                
                    /* [7] --- */
                
                };
                
                #endif // SMTPCLIENT_H
                
                

                smtpclient.cpp :

                #include "smtpclient.h"
                
                #include <QFileInfo>
                #include <QByteArray>
                #include <QTimer>
                #include <QEventLoop>
                #include <QMetaEnum>
                
                /* [1] Constructors and destructors */
                
                SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connectionType) :
                    state(UnconnectedState),
                    host(host),
                    port(port),
                    name("localhost"),
                    isReadyConnected(false),
                    isAuthenticated(false),
                    isMailSent(false),
                    isReset(false)
                {
                    setConnectionType(connectionType);
                
                    connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
                            this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
                    connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)),
                            this, SLOT(socketError(QAbstractSocket::SocketError)));
                    connect(socket, SIGNAL(readyRead()),
                            this, SLOT(socketReadyRead()));
                }
                
                SmtpClient::~SmtpClient() {}
                
                /* [1] --- */
                
                
                /* [2] Getters and Setters */
                /**
                 * @brief Returns the host name of the server.
                 */
                QString SmtpClient::getHost() const
                {
                    return this->host;
                }
                
                /**
                 * @brief Return the port.
                 */
                int SmtpClient::getPort() const
                {
                    return this->port;
                }
                
                /**
                 * @brief Returns the connection type used.
                 */
                SmtpClient::ConnectionType SmtpClient::getConnectionType() const
                {
                    return connectionType;
                }
                
                /**
                 * @brief Returns the client's name.
                 */
                QString SmtpClient::getName() const
                {
                    return this->name;
                }
                
                /**
                 * @brief Sets the client's name. This name is sent by the EHLO command.
                 */
                void SmtpClient::setName(const QString &name)
                {
                    this->name = name;
                }
                
                /**
                 * @brief Returns the last response of the server.
                 */
                QString SmtpClient::getResponseText() const
                {
                    return responseText;
                }
                
                /**
                 * @brief Returns the last response code recived by the client.
                 */
                int SmtpClient::getResponseCode() const
                {
                    return responseCode;
                }
                
                /**
                 * @brief Return the socket used by the client. The type of the of the
                 * connection is QTcpConnection in case of TcpConnection, and QSslSocket
                 * for SslConnection and TlsConnection.
                 */
                QTcpSocket* SmtpClient::getSocket() {
                    return socket;
                }
                
                /* [2] --- */
                
                
                /* [3] Public methods */
                
                void SmtpClient::connectToHost()
                {
                    if (state != UnconnectedState)
                        return;
                
                    changeState(ConnectingState);
                }
                
                void SmtpClient::login()
                {
                    if (!isReadyConnected || isAuthenticated)
                        return;
                
                    changeState(AuthenticatingState);
                }
                
                void SmtpClient::login(const QString &user, const QString &password, AuthMethod method)
                {
                    this->authInfo = AuthInfo(user, password, method);
                    login();
                }
                
                void SmtpClient::sendMail(const MimeMessage & email)
                {
                    if (!isReadyConnected)
                        return;
                
                    isMailSent = false;
                
                    this->email = &email;
                    this->rcptType = 0;
                    changeState(MailSendingState);
                }
                
                void SmtpClient::quit()
                {
                    changeState(_QUITTING_State);
                }
                
                void SmtpClient::reset()
                {
                    if (!isReadyConnected)
                        return;
                
                    isReset = false;
                
                    changeState(ResetState);
                }
                
                bool SmtpClient::waitForReadyConnected(int msec) {
                    if (state == UnconnectedState)
                        return false;
                
                    if (isReadyConnected)
                        return true;
                
                    waitForEvent(msec, SIGNAL(readyConnected()));
                
                    return isReadyConnected;
                }
                
                bool SmtpClient::waitForAuthenticated(int msec) {
                    if (!isReadyConnected)
                        return false;
                
                    if (isAuthenticated)
                        return true;
                
                    waitForEvent(msec, SIGNAL(authenticated()));
                
                    return isAuthenticated;
                }
                
                bool SmtpClient::waitForMailSent(int msec) {
                    if (!isReadyConnected)
                        return false;
                
                    if (isMailSent)
                        return true;
                
                    waitForEvent(msec, SIGNAL(mailSent()));
                
                    return isMailSent;
                }
                
                bool SmtpClient::waitForReset(int msec)
                {
                    if (!isReadyConnected)
                        return false;
                
                    if (isReset)
                        return true;
                
                    waitForEvent(msec, SIGNAL(mailReset()));
                
                    return isReset;
                }
                
                bool SmtpClient::waitForDisconnected(int msec)
                {
                
                    if (!isReadyConnected)
                        return false;
                
                    waitForEvent(msec, SIGNAL(disconnected()));
                
                    return !isReadyConnected;
                }
                
                /* [3] --- */
                
                
                /* [4] Protected methods */
                
                void SmtpClient::setConnectionType(ConnectionType ct)
                {
                    this->connectionType = ct;
                
                    switch (connectionType)
                    {
                    case TcpConnection:
                        socket = new QTcpSocket(this);
                        break;
                    case SslConnection:
                    case TlsConnection:
                        socket = new QSslSocket(this);
                        connect(socket, SIGNAL(encrypted()),
                                this, SLOT(socketEncrypted()));
                        break;
                    }
                }
                
                void SmtpClient::changeState(SmtpClient::ClientState state) {
                    this->state = state;
                
                #ifdef QT_NO_DEBUG
                    // Emit stateChanged signal only for non-internal states
                    if (state <= DisconnectingState) {
                        emit stateChanged(state);
                    }
                #else
                    // emit all in debug mode
                    qDebug() << "[SmtpClient] State:" << staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("ClientState")).valueToKey(state);
                    emit stateChanged(state);
                #endif
                
                    switch (state)
                    {
                    case ConnectingState:
                        switch (connectionType)
                        {
                        case TlsConnection:
                        case TcpConnection:
                            socket->connectToHost(host, port);
                            break;
                        case SslConnection:
                            ((QSslSocket*) socket)->connectToHostEncrypted(host, port);
                            break;
                        }
                        break;
                
                    case AuthenticatingState:
                        isAuthenticated = false;
                        changeState(authInfo.authMethod == AuthPlain ? _AUTH_PLAIN_0 : _AUTH_LOGIN_0);
                        break;
                
                    case MailSendingState:
                        isMailSent = false;
                        changeState(_MAIL_0_FROM);
                        break;
                
                    case _QUITTING_State:
                        sendMessage("QUIT");
                        break;
                
                    case DisconnectingState:
                
                        // Server should disconnect after sending reply to QUIT command, but disconnecting here takes care of a non-compliantserver.
                        socket->disconnectFromHost();
                        isReadyConnected = false;
                        break;
                
                    case UnconnectedState:
                        isReadyConnected = false;
                        isAuthenticated = false;
                
                        emit disconnected();
                        break;
                
                    case ResetState:
                        sendMessage("RSET");
                        break;
                
                    case _EHLO_State:
                        // Service ready. Send EHLO message and change the state
                        sendMessage("EHLO " + name);
                        break;
                
                    case _READY_Connected:
                        isReadyConnected = true;
                        changeState(ReadyState);
                        emit readyConnected();
                        break;
                
                    /* --- TLS --- */
                    case _TLS_State:
                        changeState(_TLS_0_STARTTLS);
                        break;
                
                    case _TLS_0_STARTTLS:
                        // send a request to start TLS handshake
                        sendMessage("STARTTLS");
                        break;
                
                    case _TLS_1_ENCRYPT:
                        ((QSslSocket*) socket)->startClientEncryption();
                        break;
                
                    case _TLS_2_EHLO:
                        // Send EHLO one more time
                        sendMessage("EHLO " + name);
                        break;
                
                    case _READY_Encrypted:
                        changeState(_READY_Connected);
                        break;
                
                    /* --- AUTH --- */
                    case _AUTH_PLAIN_0:
                        // Sending command: AUTH PLAIN base64('\0' + username + '\0' + password)
                        sendMessage("AUTH PLAIN " + QByteArray().append((char) 0).append(authInfo.username.toUtf8())
                                    .append((char) 0).append(authInfo.password.toUtf8()).toBase64());
                        break;
                
                    case _AUTH_LOGIN_0:
                        sendMessage("AUTH LOGIN");
                        break;
                
                    case _AUTH_LOGIN_1_USER:
                        // Send the username in base64
                        sendMessage(QByteArray().append(authInfo.username.toUtf8()).toBase64());
                        break;
                
                    case _AUTH_LOGIN_2_PASS:
                        // Send the password in base64
                        sendMessage(QByteArray().append(authInfo.password.toUtf8()).toBase64());
                        break;
                
                    case _READY_Authenticated:
                        isAuthenticated = true;
                        authInfo = AuthInfo();
                        changeState(ReadyState);
                        emit authenticated();
                        break;
                
                    /* --- MAIL --- */
                    case _MAIL_0_FROM:
                        sendMessage("MAIL FROM:<" + email->getSender().getAddress() + ">");
                        break;
                
                    case _MAIL_1_RCPT_INIT:
                        rcptType++;
                        const QList<EmailAddress> *addressList;
                        switch (rcptType)
                        {
                        case _TO:
                            addressList = &email->getRecipients(MimeMessage::To);
                            break;
                        case _CC:
                            addressList = &email->getRecipients(MimeMessage::Cc);
                            break;
                        case _BCC:
                            addressList = &email->getRecipients(MimeMessage::Bcc);
                            break;
                        default:
                            changeState(_MAIL_3_DATA);
                            return;
                        }
                        addressIt = addressList->constBegin();
                        addressItEnd = addressList->constEnd();
                        changeState(_MAIL_2_RCPT);
                        break;
                
                    case _MAIL_2_RCPT:
                        if (addressIt != addressItEnd) {
                            sendMessage("RCPT TO:<" + addressIt->getAddress() + ">");
                            addressIt++;
                        } else {
                            changeState(_MAIL_1_RCPT_INIT);
                        }
                        break;
                
                    case _MAIL_3_DATA:
                        sendMessage("DATA");
                        break;
                
                    case _MAIL_4_SEND_DATA:
                        email->writeToDevice(*socket);
                
                #ifndef QT_NO_DEBUG
                        qDebug() << "[Socket] OUT:";
                        qDebug() << email->toString();
                #endif
                        sendMessage("\r\n.");
                        break;
                
                    case _READY_MailSent:
                        isMailSent = true;
                        changeState(ReadyState);
                        emit mailSent();
                        break;
                
                    default:
                        ;
                    }
                }
                
                void SmtpClient::processResponse() {
                
                    switch (state)
                    {
                    case ConnectedState:
                        // Just connected to the server. Wait for 220 (Service ready)
                        if (responseCode != 220) {
                            emitError(ServerError);
                            return;
                        }
                        changeState(_EHLO_State);
                        break;
                
                    case ResetState:
                        if (responseCode != 250) {
                            emitError(ServerError);
                            return;
                        }
                        emit mailReset();
                        changeState(ReadyState);
                        break;
                
                    case _EHLO_State:
                        // The response code needs to be 250.
                        if (responseCode != 250) {
                            emitError(ServerError);
                            return;
                        }
                
                        changeState((connectionType != TlsConnection) ? _READY_Connected : _TLS_State);
                        break;
                
                    case _QUITTING_State:
                        // The response code needs to be 221.
                        if (responseCode != 221) {
                            emitError(ClientError);
                            return;
                        }
                        changeState(DisconnectingState);
                
                        break;
                
                    /* --- TLS --- */
                    case _TLS_0_STARTTLS:
                        // The response code needs to be 220.
                        if (responseCode != 220) {
                            emitError(ServerError);
                            return;
                        }
                        changeState(_TLS_1_ENCRYPT);
                        break;
                
                    case _TLS_2_EHLO:
                        // The response code needs to be 250.
                        if (responseCode != 250) {
                            emitError(ServerError);
                            return;
                        }
                        changeState(_READY_Encrypted);
                        break;
                
                    /* --- AUTH --- */
                    case _AUTH_PLAIN_0:
                        // If the response is not 235 then the authentication was failed
                        if (responseCode != 235) {
                            emitError(AuthenticationError);
                            return;
                        }
                        changeState(_READY_Authenticated);
                        break;
                
                    case _AUTH_LOGIN_0:
                        if (responseCode != 334) {
                            emitError(AuthenticationError);
                            return;
                        }
                        changeState(_AUTH_LOGIN_1_USER);
                        break;
                
                    case _AUTH_LOGIN_1_USER:
                        if (responseCode != 334) {
                            emitError(AuthenticationError);
                            return;
                        }
                        changeState(_AUTH_LOGIN_2_PASS);
                        break;
                
                    case _AUTH_LOGIN_2_PASS:
                        if (responseCode != 235) {
                            emitError(AuthenticationError);
                            return;
                        }
                        changeState(_READY_Authenticated);
                        break;
                
                    /* --- MAIL --- */
                    case _MAIL_0_FROM:
                        if (responseCode != 250) {
                            emitError(MailSendingError);
                            return;
                        }
                        changeState(_MAIL_1_RCPT_INIT);
                        break;
                
                    case _MAIL_2_RCPT:
                        if (responseCode != 250) {
                            emitError(MailSendingError);
                            return;
                        }
                        changeState(_MAIL_2_RCPT);
                        break;
                
                    case _MAIL_3_DATA:
                        if (responseCode != 354) {
                            emitError(MailSendingError);
                            return;
                        }
                        changeState(_MAIL_4_SEND_DATA);
                        break;
                
                    case _MAIL_4_SEND_DATA:
                        if (responseCode != 250) {
                            emitError(MailSendingError);
                            return;
                        }
                        changeState(_READY_MailSent);
                        break;
                
                    default:
                        ;
                    }
                }
                
                void SmtpClient::sendMessage(const QString &text)
                {
                
                #ifndef QT_NO_DEBUG
                    qDebug() << "[Socket] OUT:" << text;
                #endif
                
                    socket->write(text.toUtf8() + "\r\n");
                    socket->flush();
                }
                
                void SmtpClient::emitError(SmtpClient::SmtpError e)
                {
                    emit error(e);
                }
                
                void SmtpClient::waitForEvent(int msec, const char *successSignal)
                {
                    QEventLoop loop;
                    QObject::connect(this, successSignal, &loop, SLOT(quit()));
                    QObject::connect(this, SIGNAL(error(SmtpClient::SmtpError)), &loop, SLOT(quit()));
                
                    QTimer timer;
                    if(msec > 0)
                    {
                        timer.setSingleShot(true);
                        connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
                        timer.start(msec);
                    }
                
                    loop.exec();
                }
                
                /* [4] --- */
                
                
                /* [5] Slots for the socket's signals */
                
                void SmtpClient::socketStateChanged(QAbstractSocket::SocketState state) {
                
                #ifndef QT_NO_DEBUG
                    qDebug() << "[Socket] State:" << state;
                #endif
                
                    switch (state)
                    {
                    case QAbstractSocket::ConnectedState:
                        changeState(ConnectedState);
                
                        break;
                    case QAbstractSocket::UnconnectedState:
                        changeState(UnconnectedState);
                        break;
                    default:
                        ;
                    }
                }
                
                void SmtpClient::socketError(QAbstractSocket::SocketError socketError) {
                #ifndef QT_NO_DEBUG
                    qDebug() << "[Socket] ERROR:" << socketError;
                #else
                    Q_UNUSED(socketError);
                #endif
                    emit error(SocketError);
                }
                
                void SmtpClient::socketReadyRead()
                {
                    QString responseLine;
                
                    if (!socket->isOpen()) {
                        emitError(SocketError);
                        return;
                    }
                
                    while (socket->canReadLine()) {
                        // Save the server's response
                        responseLine = socket->readLine();
                        tempResponse += responseLine;
                
                #ifndef QT_NO_DEBUG
                        qDebug() << "[Socket] IN: " << responseLine;
                #endif
                    }
                
                
                
                    // Is this the last line of the response
                    if (responseLine.length() > 3 && responseLine[3] == ' ') {
                        responseText = tempResponse;
                        tempResponse = "";
                
                        // Extract the respose code from the server's responce (first 3 digits)
                        responseCode = responseLine.left(3).toInt();
                
                        // Check for server error
                        if (responseCode / 100 == 4) {
                            emitError(ServerError);
                            return;
                        }
                
                        // Check for client error
                        if (responseCode / 100 == 5) {
                            emitError(ClientError);
                            return;
                        }
                
                        processResponse();
                    }
                }
                
                void SmtpClient::socketEncrypted() {
                    if (state == _TLS_1_ENCRYPT) {
                        changeState(_TLS_2_EHLO);
                    }
                }
                
                /* [5] --- */
                
                SGaistS 1 Reply Last reply
                0
                • S Saee1101

                  smtpclient.h :

                  
                    Copyright (c) 2011-2012 - Tőkés Attila
                  
                    This file is part of SmtpClient for Qt.
                  
                    This library is free software; you can redistribute it and/or
                    modify it under the terms of the GNU Lesser General Public
                    License as published by the Free Software Foundation; either
                    version 2.1 of the License, or (at your option) any later version.
                  
                    This library is distributed in the hope that it will be useful,
                    but WITHOUT ANY WARRANTY; without even the implied warranty of
                    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
                    Lesser General Public License for more details.
                  
                    See the LICENSE file for more details.
                  */
                  
                  #ifndef SMTPCLIENT_H
                  #define SMTPCLIENT_H
                  
                  #include <QObject>
                  #include <QtNetwork/QSslSocket>
                  #include <QEventLoop>
                  #include "smtpmime_global.h"
                  #include "mimemessage.h"
                  
                  
                  class SMTP_MIME_EXPORT SmtpClient : public QObject
                  {
                      Q_OBJECT
                      Q_ENUMS (AuthMethod SmtpError ConnectionType ClientState)
                  public:
                  
                      /* [0] Enumerations */
                  
                      enum AuthMethod
                      {
                          AuthPlain,
                          AuthLogin
                      };
                  
                      enum SmtpError
                      {
                          ConnectionTimeoutError = 0,
                          ResponseTimeoutError = 1,
                          AuthenticationError = 2,
                          MailSendingError = 3,
                          ServerError = 4,    // 4xx smtp error
                          ClientError = 5,    // 5xx smtp error
                          SocketError = 6
                      };
                  
                      enum ConnectionType
                      {
                          TcpConnection = 0,
                          SslConnection = 1,
                          TlsConnection = 2      // STARTTLS
                      };
                  
                      enum ClientState {
                          UnconnectedState = 0,
                          ConnectingState = 1,
                          ConnectedState = 2,
                          ReadyState = 3,
                          AuthenticatingState = 4,
                          MailSendingState = 5,
                          DisconnectingState = 6,
                          ResetState = 7,
                  
                          /* Internal States */
                          _EHLO_State = 50,
                          _TLS_State = 51,
                  
                          _READY_Connected = 52,
                          _READY_Authenticated = 53,
                          _READY_MailSent = 54,
                          _READY_Encrypted = 55,
                  
                          _QUITTING_State = 56,
                  
                          /* Internal Substates */
                  
                          // TLS
                          _TLS_0_STARTTLS = 60,
                          _TLS_1_ENCRYPT = 61,
                          _TLS_2_EHLO = 62,
                  
                          // AUTH
                          _AUTH_PLAIN_0 = 70,
                          _AUTH_LOGIN_0 = 71,
                          _AUTH_LOGIN_1_USER = 72,
                          _AUTH_LOGIN_2_PASS = 73,
                  
                          // MAIL
                          _MAIL_0_FROM = 81,
                          _MAIL_1_RCPT_INIT = 82,
                          _MAIL_2_RCPT = 83,
                          _MAIL_3_DATA = 84,
                          _MAIL_4_SEND_DATA = 85
                      };
                  
                      /* [0] --- */
                  
                  
                      /* [1] Constructors and Destructors */
                  
                      SmtpClient(const QString & host = "localhost", int port = 25, ConnectionType ct = TcpConnection);
                  
                      ~SmtpClient();
                  
                      /* [1] --- */
                  
                  
                      /* [2] Getters and Setters */
                  
                      QString getHost() const;
                      int getPort() const;
                      ConnectionType getConnectionType() const;
                  
                      QString getName() const;
                      void setName(const QString &name);
                  
                      QString getResponseText() const;
                      int getResponseCode() const;
                  
                      QTcpSocket* getSocket();
                  
                      /* [2] --- */
                  
                  
                      /* [3] Public methods */
                  
                      void connectToHost();
                      void login(const QString &user, const QString &password, AuthMethod method = AuthLogin);
                      void sendMail(const MimeMessage & email);
                      void quit();
                      void reset();
                  
                      bool waitForReadyConnected(int msec = 30000);
                      bool waitForAuthenticated(int msec = 30000);
                      bool waitForMailSent(int msec = 30000);
                      bool waitForReset(int msec = 30000);
                  
                      bool waitForDisconnected(int msec = 30000);
                  
                      /* [3] --- */
                  
                  protected:
                  
                      /* [4] Protected members */
                  
                      struct AuthInfo {
                          QString username;
                          QString password;
                          AuthMethod authMethod;
                  
                          AuthInfo(const QString & username = "", const QString &password = "", AuthMethod authMethod = AuthPlain) :
                              username(username), password(password), authMethod(authMethod) {}
                      };
                  
                      QTcpSocket *socket;
                      ClientState state;
                  
                      const QString host;
                      const int port;
                      ConnectionType connectionType;
                  
                      QString name;
                  
                      AuthInfo authInfo;
                  
                      QString responseText;
                      QString tempResponse;
                      int responseCode;
                  
                      bool isReadyConnected;
                      bool isAuthenticated;
                      bool isMailSent;
                      bool isReset;
                  
                      const MimeMessage *email;
                  
                      int rcptType;
                      enum _RcptType { _TO = 1, _CC = 2, _BCC = 3};
                  
                      QList<EmailAddress>::const_iterator addressIt;
                      QList<EmailAddress>::const_iterator addressItEnd;
                  
                      /* [4] --- */
                  
                  
                      /* [5] Protected methods */
                      void login();
                      void setConnectionType(ConnectionType ct);
                      void changeState(ClientState state);
                      void processResponse();
                      void sendMessage(const QString &text);
                      void emitError(SmtpClient::SmtpError e);
                      void waitForEvent(int msec, const char *successSignal);
                  
                      /* [5] --- */
                  
                  protected slots:
                  
                      /* [6] Protected slots */
                  
                      void socketStateChanged(QAbstractSocket::SocketState state);
                      void socketError(QAbstractSocket::SocketError error);
                      void socketReadyRead();
                      void socketEncrypted();
                  
                      /* [6] --- */
                  
                  
                  signals:
                  
                      /* [7] Signals */
                  
                      void error(SmtpClient::SmtpError e);
                      void stateChanged(SmtpClient::ClientState s);
                      void connected();
                      void readyConnected();
                      void authenticated();
                      void mailSent();
                      void mailReset();
                      void disconnected();
                  
                      /* [7] --- */
                  
                  };
                  
                  #endif // SMTPCLIENT_H
                  
                  

                  smtpclient.cpp :

                  #include "smtpclient.h"
                  
                  #include <QFileInfo>
                  #include <QByteArray>
                  #include <QTimer>
                  #include <QEventLoop>
                  #include <QMetaEnum>
                  
                  /* [1] Constructors and destructors */
                  
                  SmtpClient::SmtpClient(const QString & host, int port, ConnectionType connectionType) :
                      state(UnconnectedState),
                      host(host),
                      port(port),
                      name("localhost"),
                      isReadyConnected(false),
                      isAuthenticated(false),
                      isMailSent(false),
                      isReset(false)
                  {
                      setConnectionType(connectionType);
                  
                      connect(socket, SIGNAL(stateChanged(QAbstractSocket::SocketState)),
                              this, SLOT(socketStateChanged(QAbstractSocket::SocketState)));
                      connect(socket, SIGNAL(errorOccurred(QAbstractSocket::SocketError)),
                              this, SLOT(socketError(QAbstractSocket::SocketError)));
                      connect(socket, SIGNAL(readyRead()),
                              this, SLOT(socketReadyRead()));
                  }
                  
                  SmtpClient::~SmtpClient() {}
                  
                  /* [1] --- */
                  
                  
                  /* [2] Getters and Setters */
                  /**
                   * @brief Returns the host name of the server.
                   */
                  QString SmtpClient::getHost() const
                  {
                      return this->host;
                  }
                  
                  /**
                   * @brief Return the port.
                   */
                  int SmtpClient::getPort() const
                  {
                      return this->port;
                  }
                  
                  /**
                   * @brief Returns the connection type used.
                   */
                  SmtpClient::ConnectionType SmtpClient::getConnectionType() const
                  {
                      return connectionType;
                  }
                  
                  /**
                   * @brief Returns the client's name.
                   */
                  QString SmtpClient::getName() const
                  {
                      return this->name;
                  }
                  
                  /**
                   * @brief Sets the client's name. This name is sent by the EHLO command.
                   */
                  void SmtpClient::setName(const QString &name)
                  {
                      this->name = name;
                  }
                  
                  /**
                   * @brief Returns the last response of the server.
                   */
                  QString SmtpClient::getResponseText() const
                  {
                      return responseText;
                  }
                  
                  /**
                   * @brief Returns the last response code recived by the client.
                   */
                  int SmtpClient::getResponseCode() const
                  {
                      return responseCode;
                  }
                  
                  /**
                   * @brief Return the socket used by the client. The type of the of the
                   * connection is QTcpConnection in case of TcpConnection, and QSslSocket
                   * for SslConnection and TlsConnection.
                   */
                  QTcpSocket* SmtpClient::getSocket() {
                      return socket;
                  }
                  
                  /* [2] --- */
                  
                  
                  /* [3] Public methods */
                  
                  void SmtpClient::connectToHost()
                  {
                      if (state != UnconnectedState)
                          return;
                  
                      changeState(ConnectingState);
                  }
                  
                  void SmtpClient::login()
                  {
                      if (!isReadyConnected || isAuthenticated)
                          return;
                  
                      changeState(AuthenticatingState);
                  }
                  
                  void SmtpClient::login(const QString &user, const QString &password, AuthMethod method)
                  {
                      this->authInfo = AuthInfo(user, password, method);
                      login();
                  }
                  
                  void SmtpClient::sendMail(const MimeMessage & email)
                  {
                      if (!isReadyConnected)
                          return;
                  
                      isMailSent = false;
                  
                      this->email = &email;
                      this->rcptType = 0;
                      changeState(MailSendingState);
                  }
                  
                  void SmtpClient::quit()
                  {
                      changeState(_QUITTING_State);
                  }
                  
                  void SmtpClient::reset()
                  {
                      if (!isReadyConnected)
                          return;
                  
                      isReset = false;
                  
                      changeState(ResetState);
                  }
                  
                  bool SmtpClient::waitForReadyConnected(int msec) {
                      if (state == UnconnectedState)
                          return false;
                  
                      if (isReadyConnected)
                          return true;
                  
                      waitForEvent(msec, SIGNAL(readyConnected()));
                  
                      return isReadyConnected;
                  }
                  
                  bool SmtpClient::waitForAuthenticated(int msec) {
                      if (!isReadyConnected)
                          return false;
                  
                      if (isAuthenticated)
                          return true;
                  
                      waitForEvent(msec, SIGNAL(authenticated()));
                  
                      return isAuthenticated;
                  }
                  
                  bool SmtpClient::waitForMailSent(int msec) {
                      if (!isReadyConnected)
                          return false;
                  
                      if (isMailSent)
                          return true;
                  
                      waitForEvent(msec, SIGNAL(mailSent()));
                  
                      return isMailSent;
                  }
                  
                  bool SmtpClient::waitForReset(int msec)
                  {
                      if (!isReadyConnected)
                          return false;
                  
                      if (isReset)
                          return true;
                  
                      waitForEvent(msec, SIGNAL(mailReset()));
                  
                      return isReset;
                  }
                  
                  bool SmtpClient::waitForDisconnected(int msec)
                  {
                  
                      if (!isReadyConnected)
                          return false;
                  
                      waitForEvent(msec, SIGNAL(disconnected()));
                  
                      return !isReadyConnected;
                  }
                  
                  /* [3] --- */
                  
                  
                  /* [4] Protected methods */
                  
                  void SmtpClient::setConnectionType(ConnectionType ct)
                  {
                      this->connectionType = ct;
                  
                      switch (connectionType)
                      {
                      case TcpConnection:
                          socket = new QTcpSocket(this);
                          break;
                      case SslConnection:
                      case TlsConnection:
                          socket = new QSslSocket(this);
                          connect(socket, SIGNAL(encrypted()),
                                  this, SLOT(socketEncrypted()));
                          break;
                      }
                  }
                  
                  void SmtpClient::changeState(SmtpClient::ClientState state) {
                      this->state = state;
                  
                  #ifdef QT_NO_DEBUG
                      // Emit stateChanged signal only for non-internal states
                      if (state <= DisconnectingState) {
                          emit stateChanged(state);
                      }
                  #else
                      // emit all in debug mode
                      qDebug() << "[SmtpClient] State:" << staticMetaObject.enumerator(staticMetaObject.indexOfEnumerator("ClientState")).valueToKey(state);
                      emit stateChanged(state);
                  #endif
                  
                      switch (state)
                      {
                      case ConnectingState:
                          switch (connectionType)
                          {
                          case TlsConnection:
                          case TcpConnection:
                              socket->connectToHost(host, port);
                              break;
                          case SslConnection:
                              ((QSslSocket*) socket)->connectToHostEncrypted(host, port);
                              break;
                          }
                          break;
                  
                      case AuthenticatingState:
                          isAuthenticated = false;
                          changeState(authInfo.authMethod == AuthPlain ? _AUTH_PLAIN_0 : _AUTH_LOGIN_0);
                          break;
                  
                      case MailSendingState:
                          isMailSent = false;
                          changeState(_MAIL_0_FROM);
                          break;
                  
                      case _QUITTING_State:
                          sendMessage("QUIT");
                          break;
                  
                      case DisconnectingState:
                  
                          // Server should disconnect after sending reply to QUIT command, but disconnecting here takes care of a non-compliantserver.
                          socket->disconnectFromHost();
                          isReadyConnected = false;
                          break;
                  
                      case UnconnectedState:
                          isReadyConnected = false;
                          isAuthenticated = false;
                  
                          emit disconnected();
                          break;
                  
                      case ResetState:
                          sendMessage("RSET");
                          break;
                  
                      case _EHLO_State:
                          // Service ready. Send EHLO message and change the state
                          sendMessage("EHLO " + name);
                          break;
                  
                      case _READY_Connected:
                          isReadyConnected = true;
                          changeState(ReadyState);
                          emit readyConnected();
                          break;
                  
                      /* --- TLS --- */
                      case _TLS_State:
                          changeState(_TLS_0_STARTTLS);
                          break;
                  
                      case _TLS_0_STARTTLS:
                          // send a request to start TLS handshake
                          sendMessage("STARTTLS");
                          break;
                  
                      case _TLS_1_ENCRYPT:
                          ((QSslSocket*) socket)->startClientEncryption();
                          break;
                  
                      case _TLS_2_EHLO:
                          // Send EHLO one more time
                          sendMessage("EHLO " + name);
                          break;
                  
                      case _READY_Encrypted:
                          changeState(_READY_Connected);
                          break;
                  
                      /* --- AUTH --- */
                      case _AUTH_PLAIN_0:
                          // Sending command: AUTH PLAIN base64('\0' + username + '\0' + password)
                          sendMessage("AUTH PLAIN " + QByteArray().append((char) 0).append(authInfo.username.toUtf8())
                                      .append((char) 0).append(authInfo.password.toUtf8()).toBase64());
                          break;
                  
                      case _AUTH_LOGIN_0:
                          sendMessage("AUTH LOGIN");
                          break;
                  
                      case _AUTH_LOGIN_1_USER:
                          // Send the username in base64
                          sendMessage(QByteArray().append(authInfo.username.toUtf8()).toBase64());
                          break;
                  
                      case _AUTH_LOGIN_2_PASS:
                          // Send the password in base64
                          sendMessage(QByteArray().append(authInfo.password.toUtf8()).toBase64());
                          break;
                  
                      case _READY_Authenticated:
                          isAuthenticated = true;
                          authInfo = AuthInfo();
                          changeState(ReadyState);
                          emit authenticated();
                          break;
                  
                      /* --- MAIL --- */
                      case _MAIL_0_FROM:
                          sendMessage("MAIL FROM:<" + email->getSender().getAddress() + ">");
                          break;
                  
                      case _MAIL_1_RCPT_INIT:
                          rcptType++;
                          const QList<EmailAddress> *addressList;
                          switch (rcptType)
                          {
                          case _TO:
                              addressList = &email->getRecipients(MimeMessage::To);
                              break;
                          case _CC:
                              addressList = &email->getRecipients(MimeMessage::Cc);
                              break;
                          case _BCC:
                              addressList = &email->getRecipients(MimeMessage::Bcc);
                              break;
                          default:
                              changeState(_MAIL_3_DATA);
                              return;
                          }
                          addressIt = addressList->constBegin();
                          addressItEnd = addressList->constEnd();
                          changeState(_MAIL_2_RCPT);
                          break;
                  
                      case _MAIL_2_RCPT:
                          if (addressIt != addressItEnd) {
                              sendMessage("RCPT TO:<" + addressIt->getAddress() + ">");
                              addressIt++;
                          } else {
                              changeState(_MAIL_1_RCPT_INIT);
                          }
                          break;
                  
                      case _MAIL_3_DATA:
                          sendMessage("DATA");
                          break;
                  
                      case _MAIL_4_SEND_DATA:
                          email->writeToDevice(*socket);
                  
                  #ifndef QT_NO_DEBUG
                          qDebug() << "[Socket] OUT:";
                          qDebug() << email->toString();
                  #endif
                          sendMessage("\r\n.");
                          break;
                  
                      case _READY_MailSent:
                          isMailSent = true;
                          changeState(ReadyState);
                          emit mailSent();
                          break;
                  
                      default:
                          ;
                      }
                  }
                  
                  void SmtpClient::processResponse() {
                  
                      switch (state)
                      {
                      case ConnectedState:
                          // Just connected to the server. Wait for 220 (Service ready)
                          if (responseCode != 220) {
                              emitError(ServerError);
                              return;
                          }
                          changeState(_EHLO_State);
                          break;
                  
                      case ResetState:
                          if (responseCode != 250) {
                              emitError(ServerError);
                              return;
                          }
                          emit mailReset();
                          changeState(ReadyState);
                          break;
                  
                      case _EHLO_State:
                          // The response code needs to be 250.
                          if (responseCode != 250) {
                              emitError(ServerError);
                              return;
                          }
                  
                          changeState((connectionType != TlsConnection) ? _READY_Connected : _TLS_State);
                          break;
                  
                      case _QUITTING_State:
                          // The response code needs to be 221.
                          if (responseCode != 221) {
                              emitError(ClientError);
                              return;
                          }
                          changeState(DisconnectingState);
                  
                          break;
                  
                      /* --- TLS --- */
                      case _TLS_0_STARTTLS:
                          // The response code needs to be 220.
                          if (responseCode != 220) {
                              emitError(ServerError);
                              return;
                          }
                          changeState(_TLS_1_ENCRYPT);
                          break;
                  
                      case _TLS_2_EHLO:
                          // The response code needs to be 250.
                          if (responseCode != 250) {
                              emitError(ServerError);
                              return;
                          }
                          changeState(_READY_Encrypted);
                          break;
                  
                      /* --- AUTH --- */
                      case _AUTH_PLAIN_0:
                          // If the response is not 235 then the authentication was failed
                          if (responseCode != 235) {
                              emitError(AuthenticationError);
                              return;
                          }
                          changeState(_READY_Authenticated);
                          break;
                  
                      case _AUTH_LOGIN_0:
                          if (responseCode != 334) {
                              emitError(AuthenticationError);
                              return;
                          }
                          changeState(_AUTH_LOGIN_1_USER);
                          break;
                  
                      case _AUTH_LOGIN_1_USER:
                          if (responseCode != 334) {
                              emitError(AuthenticationError);
                              return;
                          }
                          changeState(_AUTH_LOGIN_2_PASS);
                          break;
                  
                      case _AUTH_LOGIN_2_PASS:
                          if (responseCode != 235) {
                              emitError(AuthenticationError);
                              return;
                          }
                          changeState(_READY_Authenticated);
                          break;
                  
                      /* --- MAIL --- */
                      case _MAIL_0_FROM:
                          if (responseCode != 250) {
                              emitError(MailSendingError);
                              return;
                          }
                          changeState(_MAIL_1_RCPT_INIT);
                          break;
                  
                      case _MAIL_2_RCPT:
                          if (responseCode != 250) {
                              emitError(MailSendingError);
                              return;
                          }
                          changeState(_MAIL_2_RCPT);
                          break;
                  
                      case _MAIL_3_DATA:
                          if (responseCode != 354) {
                              emitError(MailSendingError);
                              return;
                          }
                          changeState(_MAIL_4_SEND_DATA);
                          break;
                  
                      case _MAIL_4_SEND_DATA:
                          if (responseCode != 250) {
                              emitError(MailSendingError);
                              return;
                          }
                          changeState(_READY_MailSent);
                          break;
                  
                      default:
                          ;
                      }
                  }
                  
                  void SmtpClient::sendMessage(const QString &text)
                  {
                  
                  #ifndef QT_NO_DEBUG
                      qDebug() << "[Socket] OUT:" << text;
                  #endif
                  
                      socket->write(text.toUtf8() + "\r\n");
                      socket->flush();
                  }
                  
                  void SmtpClient::emitError(SmtpClient::SmtpError e)
                  {
                      emit error(e);
                  }
                  
                  void SmtpClient::waitForEvent(int msec, const char *successSignal)
                  {
                      QEventLoop loop;
                      QObject::connect(this, successSignal, &loop, SLOT(quit()));
                      QObject::connect(this, SIGNAL(error(SmtpClient::SmtpError)), &loop, SLOT(quit()));
                  
                      QTimer timer;
                      if(msec > 0)
                      {
                          timer.setSingleShot(true);
                          connect(&timer, SIGNAL(timeout()), &loop, SLOT(quit()));
                          timer.start(msec);
                      }
                  
                      loop.exec();
                  }
                  
                  /* [4] --- */
                  
                  
                  /* [5] Slots for the socket's signals */
                  
                  void SmtpClient::socketStateChanged(QAbstractSocket::SocketState state) {
                  
                  #ifndef QT_NO_DEBUG
                      qDebug() << "[Socket] State:" << state;
                  #endif
                  
                      switch (state)
                      {
                      case QAbstractSocket::ConnectedState:
                          changeState(ConnectedState);
                  
                          break;
                      case QAbstractSocket::UnconnectedState:
                          changeState(UnconnectedState);
                          break;
                      default:
                          ;
                      }
                  }
                  
                  void SmtpClient::socketError(QAbstractSocket::SocketError socketError) {
                  #ifndef QT_NO_DEBUG
                      qDebug() << "[Socket] ERROR:" << socketError;
                  #else
                      Q_UNUSED(socketError);
                  #endif
                      emit error(SocketError);
                  }
                  
                  void SmtpClient::socketReadyRead()
                  {
                      QString responseLine;
                  
                      if (!socket->isOpen()) {
                          emitError(SocketError);
                          return;
                      }
                  
                      while (socket->canReadLine()) {
                          // Save the server's response
                          responseLine = socket->readLine();
                          tempResponse += responseLine;
                  
                  #ifndef QT_NO_DEBUG
                          qDebug() << "[Socket] IN: " << responseLine;
                  #endif
                      }
                  
                  
                  
                      // Is this the last line of the response
                      if (responseLine.length() > 3 && responseLine[3] == ' ') {
                          responseText = tempResponse;
                          tempResponse = "";
                  
                          // Extract the respose code from the server's responce (first 3 digits)
                          responseCode = responseLine.left(3).toInt();
                  
                          // Check for server error
                          if (responseCode / 100 == 4) {
                              emitError(ServerError);
                              return;
                          }
                  
                          // Check for client error
                          if (responseCode / 100 == 5) {
                              emitError(ClientError);
                              return;
                          }
                  
                          processResponse();
                      }
                  }
                  
                  void SmtpClient::socketEncrypted() {
                      if (state == _TLS_1_ENCRYPT) {
                          changeState(_TLS_2_EHLO);
                      }
                  }
                  
                  /* [5] --- */
                  
                  SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  Hi,

                  Where is SMTP_MIME_EXPORT defined ?

                  Is it properly activated ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply
                  0
                  • SGaistS SGaist

                    Hi,

                    Where is SMTP_MIME_EXPORT defined ?

                    Is it properly activated ?

                    S Offline
                    S Offline
                    Saee1101
                    wrote on last edited by
                    #9

                    @SGaist
                    smtpmime_global.h :

                    #ifndef SMTPMIME_GLOBAL_H
                    #define SMTPMIME_GLOBAL_H
                    
                    #ifdef SMTP_MIME_LIBRARY
                    #define SMTP_MIME_EXPORT Q_DECL_EXPORT
                    #else
                    #define SMTP_MIME_EXPORT Q_DECL_IMPORT
                    #endif
                    
                    #endif // SMTPMIME_GLOBAL_H
                    
                    
                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Saee1101
                      wrote on last edited by
                      #10

                      untitled9.pro :

                      QT  += core gui network
                      greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                      CONFIG += c++11
                      
                      # The following define makes your compiler emit warnings if you use
                      # any Qt feature that has been marked deprecated (the exact warnings
                      # depend on your compiler). Please consult the documentation of the
                      # deprecated API in order to know how to port your code away from it.
                      DEFINES += QT_DEPRECATED_WARNINGS
                      
                      # You can also make your code fail to compile if it uses deprecated APIs.
                      # In order to do so, uncomment the following line.
                      # You can also select to disable deprecated APIs only up to a certain version of Qt.
                      #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
                      
                      SOURCES += \
                          emailaddress.cpp \
                          main.cpp \
                          mainwindow.cpp \
                          mimeattachment.cpp \
                          mimebase64encoder.cpp \
                          mimebase64formatter.cpp \
                          mimebytearrayattachment.cpp \
                          mimecontentencoder.cpp \
                          mimecontentformatter.cpp \
                          mimefile.cpp \
                          mimehtml.cpp \
                          mimeinlinefile.cpp \
                          mimemessage.cpp \
                          mimemultipart.cpp \
                          mimepart.cpp \
                          mimeqpencoder.cpp \
                          mimeqpformatter.cpp \
                          mimetext.cpp \
                          quotedprintable.cpp \
                          smtpclient.cpp
                      
                      HEADERS += \
                          SmtpMime \
                          emailaddress.h \
                          mainwindow.h \
                          mimeattachment.h \
                          mimebase64encoder.h \
                          mimebase64formatter.h \
                          mimebytearrayattachment.h \
                          mimecontentencoder.h \
                          mimecontentformatter.h \
                          mimefile.h \
                          mimehtml.h \
                          mimeinlinefile.h \
                          mimemessage.h \
                          mimemultipart.h \
                          mimepart.h \
                          mimeqpencoder.h \
                          mimeqpformatter.h \
                          mimetext.h \
                          quotedprintable.h \
                          smtpclient.h \
                          smtpmime_global.h
                      
                      FORMS += \
                          mainwindow.ui
                      
                      # Default rules for deployment.
                      qnx: target.path = /tmp/$${TARGET}/bin
                      else: unix:!android: target.path = /opt/$${TARGET}/bin
                      !isEmpty(target.path): INSTALLS += target
                      
                      SUBDIRS += \
                          SMTPEmail.pro
                      
                      DISTFILES += \
                          CMakeLists.txt \
                          untitled9.pro.user
                      
                      Christian EhrlicherC 1 Reply Last reply
                      0
                      • S Saee1101

                        untitled9.pro :

                        QT  += core gui network
                        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
                        CONFIG += c++11
                        
                        # The following define makes your compiler emit warnings if you use
                        # any Qt feature that has been marked deprecated (the exact warnings
                        # depend on your compiler). Please consult the documentation of the
                        # deprecated API in order to know how to port your code away from it.
                        DEFINES += QT_DEPRECATED_WARNINGS
                        
                        # You can also make your code fail to compile if it uses deprecated APIs.
                        # In order to do so, uncomment the following line.
                        # You can also select to disable deprecated APIs only up to a certain version of Qt.
                        #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000    # disables all the APIs deprecated before Qt 6.0.0
                        
                        SOURCES += \
                            emailaddress.cpp \
                            main.cpp \
                            mainwindow.cpp \
                            mimeattachment.cpp \
                            mimebase64encoder.cpp \
                            mimebase64formatter.cpp \
                            mimebytearrayattachment.cpp \
                            mimecontentencoder.cpp \
                            mimecontentformatter.cpp \
                            mimefile.cpp \
                            mimehtml.cpp \
                            mimeinlinefile.cpp \
                            mimemessage.cpp \
                            mimemultipart.cpp \
                            mimepart.cpp \
                            mimeqpencoder.cpp \
                            mimeqpformatter.cpp \
                            mimetext.cpp \
                            quotedprintable.cpp \
                            smtpclient.cpp
                        
                        HEADERS += \
                            SmtpMime \
                            emailaddress.h \
                            mainwindow.h \
                            mimeattachment.h \
                            mimebase64encoder.h \
                            mimebase64formatter.h \
                            mimebytearrayattachment.h \
                            mimecontentencoder.h \
                            mimecontentformatter.h \
                            mimefile.h \
                            mimehtml.h \
                            mimeinlinefile.h \
                            mimemessage.h \
                            mimemultipart.h \
                            mimepart.h \
                            mimeqpencoder.h \
                            mimeqpformatter.h \
                            mimetext.h \
                            quotedprintable.h \
                            smtpclient.h \
                            smtpmime_global.h
                        
                        FORMS += \
                            mainwindow.ui
                        
                        # Default rules for deployment.
                        qnx: target.path = /tmp/$${TARGET}/bin
                        else: unix:!android: target.path = /opt/$${TARGET}/bin
                        !isEmpty(target.path): INSTALLS += target
                        
                        SUBDIRS += \
                            SMTPEmail.pro
                        
                        DISTFILES += \
                            CMakeLists.txt \
                            untitled9.pro.user
                        
                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        You are using sources from a library directly in your code so you must adjust the export macro SMTP_MIME_EXPORT to expand to nothing or use it as indented as external library.

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        S 1 Reply Last reply
                        1
                        • Christian EhrlicherC Christian Ehrlicher

                          You are using sources from a library directly in your code so you must adjust the export macro SMTP_MIME_EXPORT to expand to nothing or use it as indented as external library.

                          S Offline
                          S Offline
                          Saee1101
                          wrote on last edited by
                          #12

                          @Christian-Ehrlicher
                          Can you explain more ,please?

                          Christian EhrlicherC 1 Reply Last reply
                          0
                          • S Saee1101

                            @Christian-Ehrlicher
                            Can you explain more ,please?

                            Christian EhrlicherC Offline
                            Christian EhrlicherC Offline
                            Christian Ehrlicher
                            Lifetime Qt Champion
                            wrote on last edited by Christian Ehrlicher
                            #13

                            @Saee1101 said in C2491: 'SmtpClient::staticMetaObject': definition of dllimport static data member not allowed:

                            Can you explain more ,please?

                            you must adjust the export macro SMTP_MIME_EXPORT to expand to nothing

                            What else should I write?
                            As you can see and the error message including the MSDN documentation the SMTP_MIME_EXPORT macro expands to __declspec(dllimport) which is wrong since you simply copied the sources of this library into your own sources instead using it as a separate library. Therefore you have to adjust the macro so it expands to nothing.,

                            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                            Visit the Qt Academy at https://academy.qt.io/catalog

                            1 Reply Last reply
                            1
                            • S Saee1101 has marked this topic as solved on

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved