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. How can I use a DLL, in VS, without needing to load the moc files from the DLL?
Forum Updated to NodeBB v4.3 + New Features

How can I use a DLL, in VS, without needing to load the moc files from the DLL?

Scheduled Pinned Locked Moved Solved General and Desktop
22 Posts 4 Posters 5.4k Views 3 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.
  • AEROLASER_THAA AEROLASER_THA

    I have created a DLL with VS and Qt.
    Now I want to use that DLL, in another project, and if I manually load the moc files of the DLL project, in the current project, it works correctly.
    But, there is some way that you do not need to manually load the moc files from the DLL in the current project.

    Thank you.

    K Offline
    K Offline
    koahnig
    wrote on last edited by
    #2

    @AEROLASER_THA

    Hi and welcoem to devnet forum

    Along with the creation of the dll there is also a lib created. The lib contains the stubs for access to the dlls. You need to use the includes for your routines in your dll and you have link later on with the lib to resolve the missing modules.

    The principles are lined out in here

    Vote the answer(s) that helped you to solve your issue(s)

    1 Reply Last reply
    3
    • AEROLASER_THAA AEROLASER_THA

      I have created a DLL with VS and Qt.
      Now I want to use that DLL, in another project, and if I manually load the moc files of the DLL project, in the current project, it works correctly.
      But, there is some way that you do not need to manually load the moc files from the DLL in the current project.

      Thank you.

      AEROLASER_THAA Offline
      AEROLASER_THAA Offline
      AEROLASER_THA
      wrote on last edited by
      #3

      @AEROLASER_THA

      Dear Koahnig
      If indeed I do, and my DLL works correctly. That is, I have a DLL called AeCreator.dll, and an application called AeCretor_test.exe

      In the AeCreator_text.exe application, use the AeCreator DLL, for this in VS, for the AeCreator_text.exe project, I configured it as follows;

      (QTDIR) \ include \ QtCui \ $ (QTDIR) \ include (QTDIR) \ include (QTDIR) \ include () Include \ QtWidgets; .. \ AeCreator; .. \ AeCreator \ GeneratedFiles \ $ (ConfigurationName);% (AdditionalIncludeDirectories)

      Preprocessor:
      UNICODE; WIN64; QT_DLL; QT_NO_DEBUG; NDEBUG; QT_CORE_LIB; QT_GUI_LIB; QT_WIDGETS_LIB; AECREATOR_LIB;% (PreprocessorDefinitions)

      Linker:
      Qtmaind.lib; Qt5Cored.lib; Qt5Guid.lib; Qt5Widgetsd.lib; AeCreatord.lib;% (AdditionalDependencies)

      But for it to work properly, I must manually load the moc _ *. Cpp files from AeCreator.dll, in the AeCreator_text project, into the GeneratedFiles folder.

      In this way, the application runs correctly, but this work is very tedious, when you have a big projects with many DLLs, and in addition you have to remember that moc files correspond to those DLLs, and load them all manually.

      The query is, is there any way in VS, that when declaring the use of those DLLs, the moc files are located by the compiler without having to indicate them in the project manually?

      Thank you.

      AEROLASER_THAA 1 Reply Last reply
      0
      • AEROLASER_THAA AEROLASER_THA

        @AEROLASER_THA

        Dear Koahnig
        If indeed I do, and my DLL works correctly. That is, I have a DLL called AeCreator.dll, and an application called AeCretor_test.exe

        In the AeCreator_text.exe application, use the AeCreator DLL, for this in VS, for the AeCreator_text.exe project, I configured it as follows;

        (QTDIR) \ include \ QtCui \ $ (QTDIR) \ include (QTDIR) \ include (QTDIR) \ include () Include \ QtWidgets; .. \ AeCreator; .. \ AeCreator \ GeneratedFiles \ $ (ConfigurationName);% (AdditionalIncludeDirectories)

        Preprocessor:
        UNICODE; WIN64; QT_DLL; QT_NO_DEBUG; NDEBUG; QT_CORE_LIB; QT_GUI_LIB; QT_WIDGETS_LIB; AECREATOR_LIB;% (PreprocessorDefinitions)

        Linker:
        Qtmaind.lib; Qt5Cored.lib; Qt5Guid.lib; Qt5Widgetsd.lib; AeCreatord.lib;% (AdditionalDependencies)

        But for it to work properly, I must manually load the moc _ *. Cpp files from AeCreator.dll, in the AeCreator_text project, into the GeneratedFiles folder.

        In this way, the application runs correctly, but this work is very tedious, when you have a big projects with many DLLs, and in addition you have to remember that moc files correspond to those DLLs, and load them all manually.

        The query is, is there any way in VS, that when declaring the use of those DLLs, the moc files are located by the compiler without having to indicate them in the project manually?

        Thank you.

        AEROLASER_THAA Offline
        AEROLASER_THAA Offline
        AEROLASER_THA
        wrote on last edited by
        #4

        @AEROLASER_THA

        If the moc files belonging to the DLL project, in my case AeCreator.dll, are not loaded manually in the AeCreator_test.exe project, in the GeneratedFiles folder, the following error occurs;

        1>main.obj : error LNK2001: sÝmbolo externo "public: static struct QMetaObject const AeBaseCreatorWidget::staticMetaObject" (?staticMetaObject@AeBaseCreatorWidget@@2UQMetaObject@@B) sin resolver
        1>main.obj : error LNK2001: sÝmbolo externo "public: static struct QMetaObject const AeBaseCreatorMenu::staticMetaObject" (?staticMetaObject@AeBaseCreatorMenu@@2UQMetaObject@@B) sin resolver
        1>C:\Programacion\Lib\src\AeCreator\x64\Debug\AeCreator_Text01.exe : fatal error LNK1120: 2 externos sin resolver

        Because the AeCreator_test.exe project is not currently loading the project's moc files from the AeCreator.dll DLL.
        Is there an automatic way to indicate the necessary moc files belonging to the project of a dll, without having to load them manually?

        kshegunovK 1 Reply Last reply
        0
        • AEROLASER_THAA AEROLASER_THA

          @AEROLASER_THA

          If the moc files belonging to the DLL project, in my case AeCreator.dll, are not loaded manually in the AeCreator_test.exe project, in the GeneratedFiles folder, the following error occurs;

          1>main.obj : error LNK2001: sÝmbolo externo "public: static struct QMetaObject const AeBaseCreatorWidget::staticMetaObject" (?staticMetaObject@AeBaseCreatorWidget@@2UQMetaObject@@B) sin resolver
          1>main.obj : error LNK2001: sÝmbolo externo "public: static struct QMetaObject const AeBaseCreatorMenu::staticMetaObject" (?staticMetaObject@AeBaseCreatorMenu@@2UQMetaObject@@B) sin resolver
          1>C:\Programacion\Lib\src\AeCreator\x64\Debug\AeCreator_Text01.exe : fatal error LNK1120: 2 externos sin resolver

          Because the AeCreator_test.exe project is not currently loading the project's moc files from the AeCreator.dll DLL.
          Is there an automatic way to indicate the necessary moc files belonging to the project of a dll, without having to load them manually?

          kshegunovK Away
          kshegunovK Away
          kshegunov
          Moderators
          wrote on last edited by kshegunov
          #5

          @AEROLASER_THA said in How can I use a DLL, in VS, without needing to load the moc files from the DLL?:

          Is there an automatic way to indicate the necessary moc files belonging to the project of a dll, without having to load them manually?

          As @koahnig hinted, you don't need to have anything moc related from the dll in the app. That's one of the points of using a dll. If you get that linker error, then you should search the problem in the way you build the library, the error basically means the mocs weren't compiled into the dll (or rather the meta information wasn't exported from it).

          Have you exported the classes from said dll, which is usually the problem when you get such errors?

          Read and abide by the Qt Code of Conduct

          AEROLASER_THAA 1 Reply Last reply
          1
          • kshegunovK kshegunov

            @AEROLASER_THA said in How can I use a DLL, in VS, without needing to load the moc files from the DLL?:

            Is there an automatic way to indicate the necessary moc files belonging to the project of a dll, without having to load them manually?

            As @koahnig hinted, you don't need to have anything moc related from the dll in the app. That's one of the points of using a dll. If you get that linker error, then you should search the problem in the way you build the library, the error basically means the mocs weren't compiled into the dll (or rather the meta information wasn't exported from it).

            Have you exported the classes from said dll, which is usually the problem when you get such errors?

            AEROLASER_THAA Offline
            AEROLASER_THAA Offline
            AEROLASER_THA
            wrote on last edited by
            #6

            @kshegunov

            Dear Kshegunov;
            If I have actually declared the export of DLL classes

            #ifndef AECREATOR_GLOBAL_H
            #define AECREATOR_GLOBAL_H

            #include <QtCore/qglobal.h>

            #ifdef AECREATOR_LIB

            define AECREATOR_EXPORT Q_DECL_EXPORT

            #else

            define AECREATOR_EXPORT Q_DECL_IMPORT

            #endif
            #endif // AECREATOR_GLOBAL_H

            #include "aecreator_global.h"
            class AECREATOR_EXPORT AeBaseCreatorMenu : public QObject

            kshegunovK 1 Reply Last reply
            0
            • AEROLASER_THAA AEROLASER_THA

              @kshegunov

              Dear Kshegunov;
              If I have actually declared the export of DLL classes

              #ifndef AECREATOR_GLOBAL_H
              #define AECREATOR_GLOBAL_H

              #include <QtCore/qglobal.h>

              #ifdef AECREATOR_LIB

              define AECREATOR_EXPORT Q_DECL_EXPORT

              #else

              define AECREATOR_EXPORT Q_DECL_IMPORT

              #endif
              #endif // AECREATOR_GLOBAL_H

              #include "aecreator_global.h"
              class AECREATOR_EXPORT AeBaseCreatorMenu : public QObject

              kshegunovK Away
              kshegunovK Away
              kshegunov
              Moderators
              wrote on last edited by
              #7

              @AEROLASER_THA said in How can I use a DLL, in VS, without needing to load the moc files from the DLL?:

              class AECREATOR_EXPORT AeBaseCreatorMenu : public QObject

              And do you have the Q_OBJECT macro, I can't tell from your snippet?

              Read and abide by the Qt Code of Conduct

              AEROLASER_THAA 1 Reply Last reply
              3
              • kshegunovK kshegunov

                @AEROLASER_THA said in How can I use a DLL, in VS, without needing to load the moc files from the DLL?:

                class AECREATOR_EXPORT AeBaseCreatorMenu : public QObject

                And do you have the Q_OBJECT macro, I can't tell from your snippet?

                AEROLASER_THAA Offline
                AEROLASER_THAA Offline
                AEROLASER_THA
                wrote on last edited by kshegunov
                #8

                @kshegunov

                YES

                #ifndef AEBASECREATORMENU_H
                #define AEBASECREATORMENU_H
                
                #include "aecreator_global.h"
                
                #include <QObject>
                #include <QString>
                #include <QVariant>
                
                class QMenu;
                
                class AECREATOR_EXPORT AeBaseCreatorMenu : public QObject
                {
                	Q_OBJECT
                
                public:
                	explicit AeBaseCreatorMenu(const QString &creatorName, QObject *parent = 0);
                	virtual ~AeBaseCreatorMenu();
                
                	virtual QMenu* createMenu(QWidget *parent = 0) = 0;
                	//GET//
                	QString getName() const;
                	QVariant::Type getType() const;
                	QString getPropertyName() const;
                
                	//SET//
                	void setType(const QVariant::Type &type);
                	void setPropertyName(const QString &propertyName);
                
                private:
                	Q_DISABLE_COPY(AeBaseCreatorMenu);
                	//MEMBERS//
                	QVariant::Type type;
                	QString	name;
                	QString propertyName;
                };
                
                #endif // AEBASECREATORMENU_H
                

                [Added code tags ~kshegunov]

                kshegunovK 1 Reply Last reply
                0
                • AEROLASER_THAA AEROLASER_THA

                  @kshegunov

                  YES

                  #ifndef AEBASECREATORMENU_H
                  #define AEBASECREATORMENU_H
                  
                  #include "aecreator_global.h"
                  
                  #include <QObject>
                  #include <QString>
                  #include <QVariant>
                  
                  class QMenu;
                  
                  class AECREATOR_EXPORT AeBaseCreatorMenu : public QObject
                  {
                  	Q_OBJECT
                  
                  public:
                  	explicit AeBaseCreatorMenu(const QString &creatorName, QObject *parent = 0);
                  	virtual ~AeBaseCreatorMenu();
                  
                  	virtual QMenu* createMenu(QWidget *parent = 0) = 0;
                  	//GET//
                  	QString getName() const;
                  	QVariant::Type getType() const;
                  	QString getPropertyName() const;
                  
                  	//SET//
                  	void setType(const QVariant::Type &type);
                  	void setPropertyName(const QString &propertyName);
                  
                  private:
                  	Q_DISABLE_COPY(AeBaseCreatorMenu);
                  	//MEMBERS//
                  	QVariant::Type type;
                  	QString	name;
                  	QString propertyName;
                  };
                  
                  #endif // AEBASECREATORMENU_H
                  

                  [Added code tags ~kshegunov]

                  kshegunovK Away
                  kshegunovK Away
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #9

                  @AEROLASER_THA
                  You shouldn't pass the AECREATOR_LIB macro when building the application. And bear in mind you can't create objects of type AeBaseCreatorMenu as the class is abstract.

                  Read and abide by the Qt Code of Conduct

                  AEROLASER_THAA 1 Reply Last reply
                  0
                  • kshegunovK kshegunov

                    @AEROLASER_THA
                    You shouldn't pass the AECREATOR_LIB macro when building the application. And bear in mind you can't create objects of type AeBaseCreatorMenu as the class is abstract.

                    AEROLASER_THAA Offline
                    AEROLASER_THAA Offline
                    AEROLASER_THA
                    wrote on last edited by kshegunov
                    #10

                    @kshegunov

                    #ifndef AECREATORMENU_H
                    #define AECREATORMENU_H
                    
                    #include "aebasecreatormenu.h"
                    
                    template <class T> class AECREATOR_EXPORT  AeCreatorMenu : public AeBaseCreatorMenu
                    {
                    public:
                    	explicit AeCreatorMenu(const QString &creatorName, QObject *parent = 0)	: AeBaseCreatorMenu(creatorName, parent){};
                    	~AeCreatorMenu(){};
                    
                    	QMenu* createMenu(QWidget *parent = 0)
                    	{
                    		return static_cast<QMenu*>(new T(parent));
                    	}
                    
                    private:
                    	Q_DISABLE_COPY(AeCreatorMenu);
                    };
                    
                    #endif // AECREATORMENU_H
                    

                    [Added code tags ~kshegunov]

                    mrjjM AEROLASER_THAA 2 Replies Last reply
                    0
                    • AEROLASER_THAA AEROLASER_THA

                      @kshegunov

                      #ifndef AECREATORMENU_H
                      #define AECREATORMENU_H
                      
                      #include "aebasecreatormenu.h"
                      
                      template <class T> class AECREATOR_EXPORT  AeCreatorMenu : public AeBaseCreatorMenu
                      {
                      public:
                      	explicit AeCreatorMenu(const QString &creatorName, QObject *parent = 0)	: AeBaseCreatorMenu(creatorName, parent){};
                      	~AeCreatorMenu(){};
                      
                      	QMenu* createMenu(QWidget *parent = 0)
                      	{
                      		return static_cast<QMenu*>(new T(parent));
                      	}
                      
                      private:
                      	Q_DISABLE_COPY(AeCreatorMenu);
                      };
                      
                      #endif // AECREATORMENU_H
                      

                      [Added code tags ~kshegunov]

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by mrjj
                      #11

                      Hi
                      You are trying to export a template which wont work as class T is not yet known.
                      As far as I know, you can only export an instantiation where T is set to a type.

                      1 Reply Last reply
                      1
                      • AEROLASER_THAA AEROLASER_THA

                        @kshegunov

                        #ifndef AECREATORMENU_H
                        #define AECREATORMENU_H
                        
                        #include "aebasecreatormenu.h"
                        
                        template <class T> class AECREATOR_EXPORT  AeCreatorMenu : public AeBaseCreatorMenu
                        {
                        public:
                        	explicit AeCreatorMenu(const QString &creatorName, QObject *parent = 0)	: AeBaseCreatorMenu(creatorName, parent){};
                        	~AeCreatorMenu(){};
                        
                        	QMenu* createMenu(QWidget *parent = 0)
                        	{
                        		return static_cast<QMenu*>(new T(parent));
                        	}
                        
                        private:
                        	Q_DISABLE_COPY(AeCreatorMenu);
                        };
                        
                        #endif // AECREATORMENU_H
                        

                        [Added code tags ~kshegunov]

                        AEROLASER_THAA Offline
                        AEROLASER_THAA Offline
                        AEROLASER_THA
                        wrote on last edited by
                        #12

                        @AEROLASER_THA
                        Dear Kshegunov;
                        The problem is with any class, regardless of whether it is abstract or not. With any simple project and class.

                        If I am actually declaring AECREATOR_LIB, in the project AeCreator_test.exe

                        Preprocessor:
                        UNICODE; WIN64; QT_DLL; QT_NO_DEBUG; NDEBUG; QT_CORE_LIB; QT_GUI_LIB; QT_WIDGETS_LIB; AECREATOR_LIB;% (PreprocessorDefinitions)

                        mrjjM kshegunovK 2 Replies Last reply
                        0
                        • AEROLASER_THAA AEROLASER_THA

                          @AEROLASER_THA
                          Dear Kshegunov;
                          The problem is with any class, regardless of whether it is abstract or not. With any simple project and class.

                          If I am actually declaring AECREATOR_LIB, in the project AeCreator_test.exe

                          Preprocessor:
                          UNICODE; WIN64; QT_DLL; QT_NO_DEBUG; NDEBUG; QT_CORE_LIB; QT_GUI_LIB; QT_WIDGETS_LIB; AECREATOR_LIB;% (PreprocessorDefinitions)

                          mrjjM Offline
                          mrjjM Offline
                          mrjj
                          Lifetime Qt Champion
                          wrote on last edited by
                          #13

                          @AEROLASER_THA
                          Hi
                          Did you try something simple like
                          https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

                          It shows the step both for the DLL and for the host app.

                          AEROLASER_THAA 1 Reply Last reply
                          1
                          • AEROLASER_THAA AEROLASER_THA

                            @AEROLASER_THA
                            Dear Kshegunov;
                            The problem is with any class, regardless of whether it is abstract or not. With any simple project and class.

                            If I am actually declaring AECREATOR_LIB, in the project AeCreator_test.exe

                            Preprocessor:
                            UNICODE; WIN64; QT_DLL; QT_NO_DEBUG; NDEBUG; QT_CORE_LIB; QT_GUI_LIB; QT_WIDGETS_LIB; AECREATOR_LIB;% (PreprocessorDefinitions)

                            kshegunovK Away
                            kshegunovK Away
                            kshegunov
                            Moderators
                            wrote on last edited by
                            #14

                            @AEROLASER_THA said in How can I use a DLL, in VS, without needing to load the moc files from the DLL?:

                            If I am actually declaring AECREATOR_LIB, in the project AeCreator_test.exe

                            Which I said you shouldn't! You should define that only when building the library, not when using the library, otherwise it will not expand to __declspec(dllimport) which is mandatory on windows.

                            Read and abide by the Qt Code of Conduct

                            1 Reply Last reply
                            2
                            • mrjjM mrjj

                              @AEROLASER_THA
                              Hi
                              Did you try something simple like
                              https://wiki.qt.io/How_to_create_a_library_with_Qt_and_use_it_in_an_application

                              It shows the step both for the DLL and for the host app.

                              AEROLASER_THAA Offline
                              AEROLASER_THAA Offline
                              AEROLASER_THA
                              wrote on last edited by kshegunov
                              #15

                              @mrjj

                              //DLL test

                              //test.h

                              #include "test_global.h"
                              
                              #include <QtWidgets/QWidget>
                              
                              class TEST_EXPORT Widget : public QWidget
                              {
                              	Q_OBJECT
                              
                              public:
                                  Widget();
                              };
                              

                              //test_global.h

                              #include <QtCore/qglobal.h>
                              
                              #ifndef QT_STATIC
                              # if defined(TEST_LIB)
                              #  define TEST_EXPORT Q_DECL_EXPORT
                              # else
                              #  define TEST_EXPORT Q_DECL_IMPORT
                              # endif
                              #else
                              # define TEST_EXPORT
                              #endif
                              
                              //test.cpp
                              #include "test.h"
                              
                              Widget::Widget()
                              {
                              
                              }
                              

                              //PROJECT

                              #include <QtWidgets/QApplication>
                              
                              #include "test.h"
                              
                              int main(int argc, char *argv[])
                              {
                                  QApplication a(argc, argv);
                              	Widget w;
                              	w.resize(100, 100);
                              	w.show();
                              	return a.exec();
                              }
                              

                              //CONFIFGURATION
                              Additional Inclusion Directories;
                              .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;$(QTDIR)\include\QtWidgets;..\test;..\test\GeneratedFiles$(ConfigurationName);%(AdditionalIncludeDirectories)

                              Preprocessor;
                              UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;TEST_LIB;%(PreprocessorDefinitions)

                              Directory of additional libraries;
                              $(QTDIR)\lib;$(SolutionDir)$(Platform)$(Configuration);%(AdditionalLibraryDirectories)
                              Linker;
                              qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;test.lib;%(AdditionalDependencies)

                              If I do not load the moc_test.cpp file generated with the DLL, the following error occurs in the exe project manually;

                              main.obj : error LNK2001: símbolo externo "public: static struct QMetaObject const Widget::staticMetaObject" (?staticMetaObject@Widget@@2UQMetaObject@@B) sin resolver
                              1>c:\Users\therrera\documents\visual studio 2015\Projects\test\x64\Debug\Project.exe : fatal error LNK1120: 1 externos sin resolver

                              If you manually load the m_test.cpp file, in the project, in the GeneratedFiles folder, it runs perfectly.
                              It is as if the moc code was not contained in the DLL

                              [Added code tags ~kshegunov]

                              1 Reply Last reply
                              0
                              • mrjjM Offline
                                mrjjM Offline
                                mrjj
                                Lifetime Qt Champion
                                wrote on last edited by
                                #16

                                Hi
                                It sounds like
                                if defined(TEST_LIB)
                                define TEST_EXPORT Q_DECL_EXPORT
                                is active when you build the app ?

                                In sample the key points are
                                TEMPLATE = lib <<<
                                DEFINES += TEST<<<
                                for the LIB, not app.

                                So how are you controlling the TEST_LIB when building the lib and the app ?
                                for the app, TEST_LIB is not to be defined.

                                AEROLASER_THAA 1 Reply Last reply
                                2
                                • mrjjM mrjj

                                  Hi
                                  It sounds like
                                  if defined(TEST_LIB)
                                  define TEST_EXPORT Q_DECL_EXPORT
                                  is active when you build the app ?

                                  In sample the key points are
                                  TEMPLATE = lib <<<
                                  DEFINES += TEST<<<
                                  for the LIB, not app.

                                  So how are you controlling the TEST_LIB when building the lib and the app ?
                                  for the app, TEST_LIB is not to be defined.

                                  AEROLASER_THAA Offline
                                  AEROLASER_THAA Offline
                                  AEROLASER_THA
                                  wrote on last edited by
                                  #17

                                  @mrjj
                                  Yes, is active

                                  //DLL
                                  Preprocessor;
                                  UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;TEST_LIB;%(PreprocessorDefinitions)
                                  Linker;
                                  qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;%(AdditionalDependencies)

                                  //PROJECT
                                  Preprocessor;
                                  UNICODE;WIN32;WIN64;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;QT_WIDGETS_LIB;TEST_LIB;%(PreprocessorDefinitions)
                                  Linker;
                                  qtmaind.lib;Qt5Cored.lib;Qt5Guid.lib;Qt5Widgetsd.lib;test.lib;%(AdditionalDependencies)

                                  But it only runs correctly, if in the project manually load the moc_test.cpp

                                  1 Reply Last reply
                                  0
                                  • mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #18

                                    So you are 100% sure that its Q_DECL_IMPORT when building the app and
                                    Q_DECL_EXPORT when building the LIB/DLL ?
                                    Sorry I cannot see it from your output.
                                    Both seems to say TEST_LIB; which is wrong.
                                    Only
                                    //DLL
                                    Preprocessor;
                                    should have it.

                                    AEROLASER_THAA 1 Reply Last reply
                                    0
                                    • mrjjM mrjj

                                      So you are 100% sure that its Q_DECL_IMPORT when building the app and
                                      Q_DECL_EXPORT when building the LIB/DLL ?
                                      Sorry I cannot see it from your output.
                                      Both seems to say TEST_LIB; which is wrong.
                                      Only
                                      //DLL
                                      Preprocessor;
                                      should have it.

                                      AEROLASER_THAA Offline
                                      AEROLASER_THAA Offline
                                      AEROLASER_THA
                                      wrote on last edited by
                                      #19

                                      @mrjj

                                      TEST_LIB is declared in both DLL and Project

                                      If I do not declare in Project, in preprocessor, it gives me error.

                                      moc_test.cpp
                                      1>..\test\GeneratedFiles\Debug\moc_test.cpp(56): warning C4273: 'Widget::qt_static_metacall': vinculación de DLL incoherente
                                      1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'qt_static_metacall'
                                      1>..\test\GeneratedFiles\Debug\moc_test.cpp(63): warning C4273: 'staticMetaObject': vinculación de DLL incoherente
                                      1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'public: static QMetaObject const Widget::staticMetaObject'
                                      1>..\test\GeneratedFiles\Debug\moc_test.cpp(63): error C2491: 'Widget::staticMetaObject': definición de miembro de datos estático dllimport no permitida
                                      1>..\test\GeneratedFiles\Debug\moc_test.cpp(70): warning C4273: 'Widget::metaObject': vinculación de DLL incoherente
                                      1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'metaObject'
                                      1>..\test\GeneratedFiles\Debug\moc_test.cpp(75): warning C4273: 'Widget::qt_metacast': vinculación de DLL incoherente
                                      1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'qt_metacast'
                                      1>..\test\GeneratedFiles\Debug\moc_test.cpp(83): warning C4273: 'Widget::qt_metacall': vinculación de DLL incoherente
                                      1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'qt_metacall'
                                      1> main.cpp

                                      mrjjM 1 Reply Last reply
                                      0
                                      • AEROLASER_THAA AEROLASER_THA

                                        @mrjj

                                        TEST_LIB is declared in both DLL and Project

                                        If I do not declare in Project, in preprocessor, it gives me error.

                                        moc_test.cpp
                                        1>..\test\GeneratedFiles\Debug\moc_test.cpp(56): warning C4273: 'Widget::qt_static_metacall': vinculación de DLL incoherente
                                        1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'qt_static_metacall'
                                        1>..\test\GeneratedFiles\Debug\moc_test.cpp(63): warning C4273: 'staticMetaObject': vinculación de DLL incoherente
                                        1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'public: static QMetaObject const Widget::staticMetaObject'
                                        1>..\test\GeneratedFiles\Debug\moc_test.cpp(63): error C2491: 'Widget::staticMetaObject': definición de miembro de datos estático dllimport no permitida
                                        1>..\test\GeneratedFiles\Debug\moc_test.cpp(70): warning C4273: 'Widget::metaObject': vinculación de DLL incoherente
                                        1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'metaObject'
                                        1>..\test\GeneratedFiles\Debug\moc_test.cpp(75): warning C4273: 'Widget::qt_metacast': vinculación de DLL incoherente
                                        1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'qt_metacast'
                                        1>..\test\GeneratedFiles\Debug\moc_test.cpp(83): warning C4273: 'Widget::qt_metacall': vinculación de DLL incoherente
                                        1> c:\users\therrera\documents\visual studio 2015\projects\test\test\generatedfiles\debug../../test.h(10): note: vea la definición anterior de 'qt_metacall'
                                        1> main.cpp

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #20

                                        @AEROLASER_THA
                                        hmm. ok. im going to try the small test project and see.
                                        You added a UI files also ?

                                        1 Reply Last reply
                                        0
                                        • AEROLASER_THAA Offline
                                          AEROLASER_THAA Offline
                                          AEROLASER_THA
                                          wrote on last edited by
                                          #21

                                          In this example, I am not using ui files

                                          AEROLASER_THAA 1 Reply Last reply
                                          0

                                          • Login

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