why definition is talking from .cpp file?



  • 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?


  • Qt Champions 2018

    does AbstractExperiment.h have #include <QWidget>?



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


  • Qt Champions 2018

    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)



  • 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.



  • @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.


  • Qt Champions 2018

    @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.