1

Im trying to make custom widget in Qt with Qwt extension via Add >> New Item >> Qt Class. My enviroment :

  • Visual studio 2022
  • Qt 5.12.2
  • Qwt 6.2.0
  • Qt Creator 6.4.0

I successfully executed custom widget with QLabel base class but I can't successfully use QwtPlot class. I get this type of error:

Error:

I tried to find digestible answer but there is only something with moc_ files for Qwt. I added those in include file, but nothing works.

custom widget class waterlooo.h

#ifndef WATERLOOO_H
#define WATERLOOO_H

#include "qwt_plot_curve.h"
#include <vector>

#include <QwtPlot>
#include "qobject.h"

using std::vector;

class Waterlooo  : public QwtPlot
{
    Q_OBJECT

public:
    Waterlooo(QWidget *parent = nullptr);
    ~Waterlooo();


    void plotujkur(vector<float> x, vector<float> y, int fftecka);
};

#endif

custom widget class waterlooo.cpp

#include "waterlooo.h"

Waterlooo::Waterlooo(QWidget *parent)
    : QwtPlot(parent)
{
    this->setAutoFillBackground(true);
    this->setPalette(Qt::white);
    this->setCanvasBackground(Qt::white);


}

Waterlooo::~Waterlooo()
{}


void Waterlooo::plotujkur(vector<float> x, vector<float> y, int fftecka)
{
    QwtPlotCurve* curve1 = new QwtPlotCurve;
    curve1->setSamples(&x[0], &y[0], fftecka);
    curve1->setPen(QColor(Qt::green));
    curve1->attach(this);
    this->replot();
}
Miro Bozon
  • 21
  • 4
  • The linker error looks like either moc was not called for this file or its generated source was not built. – drescherjm Jan 17 '23 at 14:17
  • And please how should I do that in visual studio? It generate moc for this class but in a different file. – Miro Bozon Jan 17 '23 at 15:15
  • ***And please how should I do that in visual studio?*** It's unclear how you are building. I use CMake + Visual Studio + Qt for all applications at work since 2008 but don't have a lot of experience in any other method. – drescherjm Jan 17 '23 at 15:26
  • ***It generate moc for this class but in a different file.*** Make sure you add that source file to the list of sources in Solution Explorer. It should show up in the "Source Files" – drescherjm Jan 17 '23 at 15:27
  • I have it same way as it is on the picture in question. So I have waterlooo.cpp in my project as source file. – Miro Bozon Jan 18 '23 at 06:15
  • I compile the .h file of my custom widget and it generates moc_ .cpp file to x64/Debuf/moc file. I added this file to my source file and now I get: Cannot open source file ';': No sich file or directory. – Miro Bozon Jan 18 '23 at 08:40
  • Here is a possible solution to the similar issue: https://stackoverflow.com/a/30986008/13327906 – K13 Apr 13 '23 at 12:31

0 Answers0