Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

[Solved]: Implementing an abstract class within an qt-creator project



  • Hi,

    to plot a smoother mathematical curve with qwt using qt-creator, as the default doesn't look really good, the qwt-developer pointed me to QwtSyntheticPointData

    which is an abstract class. But I have not been able to figure out, how I could integrate it into a standard qt-creator project. Obviously I need write my own class based on the abstract one. But how do I do that within a qt-creator project?

    Thanks in advance,

    Kind regards,

    Andreas


  • Lifetime Qt Champion

    Hi,

    Qt Creator provides a wizard to add new classes to your project.



  • Thanks, I'll look into that this evening and report back

    Kind regards,

    Andreas



  • Finally, i found the time to search for the class wizard, but i have been unable to find it in the german version of qt creator. Do i need to add it somehow or configure qt creator in a certain way?

    Isn't there some kind of tutorial to add a class to an existing project "by hand"? It is difficult to find something like that on the internet, as there are too many results, when searching for rather generic keywords.


  • Moderators

    @andi456 right mouse button on over all project folder, -> "Hinzuf├╝gen" -> C++ -> C++ Klasse



  • Thanks, it's sometimes hard to get used to all the functions of an IDE. Unfortunately, this led me only back to the problem, that i was hoping solve anyway. I've got the empty header and empty source file, and the IDE or compiler tells me the following:

    "Error constructor for 'WageCurvePoints' must explicitly initialize the base class 'QwtSyntheticPointData' which does not have a default constructor"

    I haven't been able to figure out how to accomplish the initialization of the base class. I tried to adapt the example given in the source code of 'QwtSyntheticPointData', but couldn't make it work....


  • Lifetime Qt Champion

    Can you show the code you have ?



  • Sure, as i said, i just tried to implement the simple sine example of the man page of QwtSyntheticPointData so the name WageCurvePoints is a little misleading. The problem seems to be that there is no header file in the example. So this is, what i put in the header file:

    #ifndef WAGECURVEPOINTS_H
    #define WAGECURVEPOINTS_H
    #include "qwt6/qwt_point_data.h"

    class WageCurvePoints : public QwtSyntheticPointData
    {
    public:
    WageCurvePoints():
    QwtSyntheticPointData( 100 )
    {
    }

    virtual double y( double x ) const
    {
        return qSin( x );
    }
    

    };

    #endif // WAGECURVEPOINTS_H

    In the cpp file there's nothing more than that, what the wizard created resulting in the above error message:

    #include "wagecurvepoints.h"

    WageCurvePoints::WageCurvePoints()
    {

    };


  • Lifetime Qt Champion

    Well, you have two different implementations of the same constructor. Either remove the one from the .cpp file or move the one from your header and replace the version you have in the .cpp.



  • @SGaist : Thanks again, it worked by putting all the code into the header file. I could not figure out which way would be more "correct".


Log in to reply