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. why definition is talking from .cpp file?
QtWS25 Last Chance

why definition is talking from .cpp file?

Scheduled Pinned Locked Moved General and Desktop
c++qt 5.11.0dllvirtual
7 Posts 3 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.
  • Y Offline
    Y Offline
    Yash001
    wrote on last edited by Yash001
    #1

    AbstractExperiment.h

    class AbstractExperiment {
    public:
    	
        AbstractExperiment() {};
        virtual QString GetShortName() const = 0;
        virtual QWidget* CreateUserInput() const = 0;
    	virtual QString GetExpParamTxt(QWidget*)const;
    };
    Q_DECLARE_METATYPE(AbstractExperiment*)
    Q_DECLARE_METATYPE(const AbstractExperiment*)
    
    

    AbstractExperiment.cpp

    QString AbstractExperiment::GetExpParamTxt(QWidget*) const {
    	QString ret = ""; 
    	return ret; 
    }
    

    ExperimentFactoryInterface.h

    #pragma once
    
    #include <QVariant>
    
    #include <AbstractExperiment.h>
    
    class ExperimentFactoryInterface {
    public:
    	virtual ~ExperimentFactoryInterface() {}
    	virtual AbstractExperiment* CreateExperiment(const QVariant& = QVariant()) = 0;
    };
    
    Q_DECLARE_INTERFACE(ExperimentFactoryInterface, "ExperimentFactoryInterface")
    

    Experiment.h

    #ifndef CYCLICVOLTAMMETRY_H
    #define CYCLICVOLTAMMETRY_H
    
    #include <AbstractExperiment.h>
    #include <QtWidgets/QWidget>
    
    class StaircaseVoltammetry : public AbstractExperiment {
    public:
    	QString GetShortName() const;
    	QWidget* CreateUserInput() const;
    	QString GetExpParamTxt(QWidget* wdg)const ;
    
    };
    

    Factory.h

    #pragma once
    
    #include <ExperimentFactoryInterface.h>
    
    class Factory : public QObject, public ExperimentFactoryInterface {
    	Q_OBJECT
    	Q_PLUGIN_METADATA(IID "ExperimentFactoryInterface")
    	Q_INTERFACES(ExperimentFactoryInterface)
    
    public:
    	AbstractExperiment* CreateExperiment(const QVariant& = QVariant());
    };
    

    I have virtual QString GetExpParamTxt(QWidget*)const; function in AbstractExperiment.h, which is not pure virtual function.

    If I will right the definitionGetExpParamTxt in AbstractExperiment.h is compile perfectly but I define the function definition in AbstractExperiment.cpp then I am getting error like below.

    0_1557248688139_91a1ed54-0017-4da8-b03b-12eb756cc2c9-image.png

    I am creating dll file for Experiment file.

    what is change do I require for make it work?

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      does AbstractExperiment.h have #include <QWidget>?

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      Y 1 Reply Last reply
      0
      • VRoninV VRonin

        does AbstractExperiment.h have #include <QWidget>?

        Y Offline
        Y Offline
        Yash001
        wrote on last edited by
        #3

        @VRonin
        Yes it is include through another file. Like I have #include <ExperimentUIHelper.h> contain #include <QWidget>, and AbstractExperiment.h contain #include <ExperimentUIHelper.h>.

        1 Reply Last reply
        0
        • Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          When you create a shared library you have to export your functions you want to use from outside since by default all symbols are hidden on windows (in contrast to linux where all is visible)

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

          Y 1 Reply Last reply
          3
          • Y Offline
            Y Offline
            Yash001
            wrote on last edited by Yash001
            #5

            Here I mention compiler output. ignore about other virtual function. it is program same as GetExpParamTxt. 0_1557250473955_Capture.PNG

            Here few other static function I mention in AbstractExperiment.h it is also giving me error if i will write definition in AbstractExperiment.cpp. In general, If I will define the function in AbstractExperiment.h file then Experiment file is able to read the definition from the base class. if I will mention definition in AbstractExperiment.cpp then derived class does not able to read the definition of base class function.

            1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              When you create a shared library you have to export your functions you want to use from outside since by default all symbols are hidden on windows (in contrast to linux where all is visible)

              Y Offline
              Y Offline
              Yash001
              wrote on last edited by
              #6

              @Christian-Ehrlicher

              I know about Q_DECL_EXPORT. Here what I am doing. I am including AbstractExperiment.h in main project. and experiment is created in another sub project, sub project class is derived from AbstractExperiment, and derived class is used functionality of base class (AbstractExperiment).

              just curious to know. If AbstractExperiment is not exporting function then why it is working if I will define the definition inside the class AbstractExperiment.

              just now I try Q_DECL_EXPORT virtual QString GetExpParamTxt(QWidget*)const;. I got same error.

              1 Reply Last reply
              0
              • Christian EhrlicherC Online
                Christian EhrlicherC Online
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Yash001 said in why definition is talking from .cpp file?:

                why it is working if I will define the definition inside the class

                Because then the compiler sees the definition when you compile your executable.

                just now I try Q_DECL_EXPORT virtual QString GetExpParamTxt(QWidget*)const;. I got same error.

                You did not read the link carefully... you have to export it when compiling the lib, import it when linking against as explained.

                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
                4

                • Login

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