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. MSVC 2019: DLLImport static data member not allowed
Qt 6.11 is out! See what's new in the release blog

MSVC 2019: DLLImport static data member not allowed

Scheduled Pinned Locked Moved Solved General and Desktop
12 Posts 4 Posters 7.1k 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.
  • kshegunovK Offline
    kshegunovK Offline
    kshegunov
    Moderators
    wrote on last edited by
    #3

    Interfaces don't have members, and they for sure don't derive from QObject. There's a pretty decent example in the documentation, you should follow it.

    Read and abide by the Qt Code of Conduct

    F 1 Reply Last reply
    0
    • hskoglundH hskoglund

      Hi, it might be something missing in the .pro file for the plugin project, it should have a line like this:

      ...
      DEFINES += PLUGIN_LIBRARY
      ...
      
      F Offline
      F Offline
      fem_dev
      wrote on last edited by fem_dev
      #4

      @hskoglund said in MSVC 2019: DLLImport static data member not allowed:

      DEFINES += PLUGIN_LIBRARY

      Thank you for your quick response...
      First: It works and solved my error and all warnings in the MSVC compilation!

      But I don't get your point with this define line.
      Why this line fixed my problem?

      1 Reply Last reply
      0
      • hskoglundH Offline
        hskoglundH Offline
        hskoglund
        wrote on last edited by
        #5

        While I haven't built any Qt plugins, but if they are built the same way normal .dlls are, then the error you get " ...import ... not allowed" when compiling your plugin, could be due to that missing #define.

        If you look in the plugin_global.h file, the error maybe can occur if
        #define PLUGIN_EXPORT Q_DECL_EXPORT
        gets #defined rather than
        #define PLUGIN_EXPORT Q_DECL_IMPORT

        (i..e the plugin should be exporting its functions, not importing them)

        F 1 Reply Last reply
        1
        • kshegunovK kshegunov

          Interfaces don't have members, and they for sure don't derive from QObject. There's a pretty decent example in the documentation, you should follow it.

          F Offline
          F Offline
          fem_dev
          wrote on last edited by
          #6

          @kshegunov said in MSVC 2019: DLLImport static data member not allowed:

          There's a pretty decent example in the documentation, you should follow it.

          Thank you for your attention.
          Could you please give me links about this information?

          I follow this Qt Wiki tutorial below:
          https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

          And now I saw this Qt 5.15.0 little explanation here:
          https://doc.qt.io/qt-5/sharedlibrary.html

          Like you said before, may be I'm doing something wrong and I would like to do it right!

          I derived my interface from QObject because I saw it on a Udemy Qt online course...
          I was thinking that this was "the right way" to add the same set of signals and slots for all developed plugins.

          But I would like to do that in the best possible way.
          Please @kshegunov , if is there a better way, feel free to comment about it.

          Thank you!

          jsulmJ F 2 Replies Last reply
          0
          • hskoglundH hskoglund

            While I haven't built any Qt plugins, but if they are built the same way normal .dlls are, then the error you get " ...import ... not allowed" when compiling your plugin, could be due to that missing #define.

            If you look in the plugin_global.h file, the error maybe can occur if
            #define PLUGIN_EXPORT Q_DECL_EXPORT
            gets #defined rather than
            #define PLUGIN_EXPORT Q_DECL_IMPORT

            (i..e the plugin should be exporting its functions, not importing them)

            F Offline
            F Offline
            fem_dev
            wrote on last edited by
            #7

            @hskoglund said in MSVC 2019: DLLImport static data member not allowed:

            missing #define.

            #ifndef PLUGIN_GLOBAL_H
            #define PLUGIN_GLOBAL_H
            
            #include <QtCore/qglobal.h>
            
            #if defined(PLUGIN_LIBRARY) // HERE IS WHY YOU NEED TO PASS THIS DEFINE AT COMPILATION TIME
            #  define PLUGIN_EXPORT Q_DECL_EXPORT
            #else
            #  define PLUGIN_EXPORT Q_DECL_IMPORT
            #endif
            
            #endif // PLUGIN_GLOBAL_H
            

            Brilhant @hskoglund ! Thank you so much!

            1 Reply Last reply
            0
            • F fem_dev

              @kshegunov said in MSVC 2019: DLLImport static data member not allowed:

              There's a pretty decent example in the documentation, you should follow it.

              Thank you for your attention.
              Could you please give me links about this information?

              I follow this Qt Wiki tutorial below:
              https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

              And now I saw this Qt 5.15.0 little explanation here:
              https://doc.qt.io/qt-5/sharedlibrary.html

              Like you said before, may be I'm doing something wrong and I would like to do it right!

              I derived my interface from QObject because I saw it on a Udemy Qt online course...
              I was thinking that this was "the right way" to add the same set of signals and slots for all developed plugins.

              But I would like to do that in the best possible way.
              Please @kshegunov , if is there a better way, feel free to comment about it.

              Thank you!

              jsulmJ Online
              jsulmJ Online
              jsulm
              Lifetime Qt Champion
              wrote on last edited by
              #8

              @fem_dev said in MSVC 2019: DLLImport static data member not allowed:

              I follow this Qt Wiki tutorial below:
              https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

              This is for normal libraries, not plug-ins.
              If you want to implement a plug-in why not following https://doc.qt.io/qt-5/plugins-howto.html ?
              There are links to examples...

              https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              3
              • F fem_dev

                @kshegunov said in MSVC 2019: DLLImport static data member not allowed:

                There's a pretty decent example in the documentation, you should follow it.

                Thank you for your attention.
                Could you please give me links about this information?

                I follow this Qt Wiki tutorial below:
                https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

                And now I saw this Qt 5.15.0 little explanation here:
                https://doc.qt.io/qt-5/sharedlibrary.html

                Like you said before, may be I'm doing something wrong and I would like to do it right!

                I derived my interface from QObject because I saw it on a Udemy Qt online course...
                I was thinking that this was "the right way" to add the same set of signals and slots for all developed plugins.

                But I would like to do that in the best possible way.
                Please @kshegunov , if is there a better way, feel free to comment about it.

                Thank you!

                F Offline
                F Offline
                fem_dev
                wrote on last edited by fem_dev
                #9

                @fem_dev said in MSVC 2019: DLLImport static data member not allowed:

                But I would like to do that in the best possible way.

                In this case that I want to give the same set of signals and slots to all my develop plugins should I:

                • Remove all variable members, QObject and signals and slots from the Plugin_API class (interface)
                • create a new class (Base_Plugin class)
                • In this Base_Plugin add all signals and slots
                • In this Base_Plugin add all variable members that are commum to all plugins
                • For each Plugin derive like:
                class PLUGIN_EXPORT Plugin : public QObject, public Base_Plugin, public Plugin_API
                {
                ...
                    all_methods override;
                ...
                }`
                

                Is this the right way?
                @hskoglund @kshegunov @jsulm

                jsulmJ 1 Reply Last reply
                0
                • F fem_dev

                  @fem_dev said in MSVC 2019: DLLImport static data member not allowed:

                  But I would like to do that in the best possible way.

                  In this case that I want to give the same set of signals and slots to all my develop plugins should I:

                  • Remove all variable members, QObject and signals and slots from the Plugin_API class (interface)
                  • create a new class (Base_Plugin class)
                  • In this Base_Plugin add all signals and slots
                  • In this Base_Plugin add all variable members that are commum to all plugins
                  • For each Plugin derive like:
                  class PLUGIN_EXPORT Plugin : public QObject, public Base_Plugin, public Plugin_API
                  {
                  ...
                      all_methods override;
                  ...
                  }`
                  

                  Is this the right way?
                  @hskoglund @kshegunov @jsulm

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #10

                  @fem_dev See "The Low-Level API: Extending Qt Applications" in the link I posted.
                  There is no need for two classes Base_Plugin and Plugin_API.
                  Implement one interface class and derive your Plugin from it and QObject as shown in the example.

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  F 1 Reply Last reply
                  3
                  • jsulmJ jsulm

                    @fem_dev See "The Low-Level API: Extending Qt Applications" in the link I posted.
                    There is no need for two classes Base_Plugin and Plugin_API.
                    Implement one interface class and derive your Plugin from it and QObject as shown in the example.

                    F Offline
                    F Offline
                    fem_dev
                    wrote on last edited by
                    #11

                    @jsulm said in MSVC 2019: DLLImport static data member not allowed:

                    There is no need for two classes Base_Plugin and Plugin_API.

                    Thank you for the informations.
                    Doubt:
                    If the interface doesn't derive from QObject, how can I use signals and slots between my main app and a plugin?

                    jsulmJ 1 Reply Last reply
                    0
                    • F fem_dev

                      @jsulm said in MSVC 2019: DLLImport static data member not allowed:

                      There is no need for two classes Base_Plugin and Plugin_API.

                      Thank you for the informations.
                      Doubt:
                      If the interface doesn't derive from QObject, how can I use signals and slots between my main app and a plugin?

                      jsulmJ Online
                      jsulmJ Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #12

                      @fem_dev said in MSVC 2019: DLLImport static data member not allowed:

                      If the interface doesn't derive from QObject, how can I use signals and slots between my main app and a plugin?

                      If the interface class does not derive from QObject it can still create and return instances of QObject derived classes.

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      2

                      • Login

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