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. Keep getting " expected initializer before ':' when declaring dll
QtWS25 Last Chance

Keep getting " expected initializer before ':' when declaring dll

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 1.4k Views
  • 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.
  • L Offline
    L Offline
    Loc888
    wrote on 20 Mar 2022, 18:45 last edited by
    #1

    I keep getting some invented errors by the compiler
    " expected initializer before ':' token class EXPORT Color_Class : public QColor"

    I have no clue why this thing doesn't work, i had this error before so i added into the project DEFINES += CL_LIB_LIBRARY

    This is the macro, which i put the export/import macro
    #define EXPORT CL_LIBSHARED_EXPORT

    #pragma once
    #include <QtCore/qglobal.h>
    
    #if defined(CL_LIB_LIBRARY)
    #  define CL_LIBSHARED_EXPORT Q_DECL_EXPORT
    #else
    #  define CL_LIBSHARED_EXPORT Q_DECL_IMPORT
    #endif
    

    Here the error occurs "class EXPORT Color_Class : public QColor"
    The error occurs with few clasess, but this one is the first, i have like 300 clasess, and none of them has the same errors.. I tried to look it up since it should be a bassic error, but none, just whatever i do, same errors occur over and over, just some random invention to waste peoples time..

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 20 Mar 2022, 19:31 last edited by
      #2

      @Loc888 said in Keep getting " expected initializer before ':' when declaring dll:

      CL_LIBSHARED_EXPORT

      This should be used, not an extra macro

      class CL_LIBSHARED_EXPORT Color_Class : public QColor

      When you compile your lib you have to add "DEFINES += CL_LIB_LIBRARY" to your pro file, when you use it, this define must not be set.

      btw: why do you need to derive from QColor?

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

      L 1 Reply Last reply 21 Mar 2022, 05:17
      1
      • C Christian Ehrlicher
        20 Mar 2022, 19:31

        @Loc888 said in Keep getting " expected initializer before ':' when declaring dll:

        CL_LIBSHARED_EXPORT

        This should be used, not an extra macro

        class CL_LIBSHARED_EXPORT Color_Class : public QColor

        When you compile your lib you have to add "DEFINES += CL_LIB_LIBRARY" to your pro file, when you use it, this define must not be set.

        btw: why do you need to derive from QColor?

        L Offline
        L Offline
        Loc888
        wrote on 21 Mar 2022, 05:17 last edited by Loc888
        #3

        @Christian-Ehrlicher It doesn't change anything, i tried to do it the last day, but still it doesn't work, even if i remove the define and change it to CL_LIBSHARED_EXPORT.

        That EXPORT is a macro to another macro, so it must works, and also it worked for more then half year..

        What is the most weird, is if i make it an empty macro so:

        #define EXPORT
        class EXPORT Color_Class  : public QColor
        

        the error will still be there....

        BUT if i make a new macro

        #define ABCD
        class ABCD Color_Class  : public QColor
        

        Then at that point the error disapear, you tell me what is even this thing...
        I still have 8 other errors which are:

        variable 'EXPORT Color_Sets' has initializer but incomplete type
        struct EXPORT Color_Sets
        ---------------^~~~~~~~~~~~~~~~~~

        expected primary-expression before 'public'
        public:
        -^~~~~~

        expected '}' before 'public'

        expected ',' or ';' before 'public'

        'Color_Class ' does not name a type;
        -----Color_Class max;
        -----^~~~~~~~~~

        expected unqualified-id before 'public'
        public:
        -^~~~~~

        non-member function 'QString min_to_text()' cannot have cv-qualifier
        -----QString min_to_text() const;
        ^~~~~

        non-member function 'QString max_to_text()' cannot have cv-qualifier
        -----QString max_to_text() const;
        ^~~~~

        expected declaration before '}' token
        --};
        ^

        I have trully no clue what is this thing, i can compile the dll without any problems, so it's not a problem of some missing "}" or so... And the fact that same stuff occurs with an empty macro just speaks for it's self, that something buggy is going on.

        1 Reply Last reply
        0
        • L Offline
          L Offline
          Loc888
          wrote on 21 Mar 2022, 05:53 last edited by Loc888
          #4

          I found the problem... It was because i had 2 .hpp named the same way, one was with some other macros i used to code, and the second one was with the export macro alone..

          They had both the same paths, so in the dll project it was let's say src/macros/defines.hpp, and in the app project where i import the dll it was the same, but i don't understand why when i was clicking on it, it was reffering me to the valid file which i wanted to use.

          Also, it worked for half a year, so i didn't bother to change it, probably it worked because the files didn't come in conflict, but since i changed a lot of paths in the dll project, it stopped working, and that's why i got the weird errors, the hpp was set to pragma once and the wrong file was applied, so the compiled treated it as some invalid syntax letters, still the macro in the editor was looking like it was applied, that's what fooled me.

          1 Reply Last reply
          1

          1/4

          20 Mar 2022, 18:45

          • Login

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