Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
69 views
in Technique[技术] by (71.8m points)

c++ - No member named 'setText' error in qt custom class

I have made a custom qt class , odometer which inherits from QWidget , everything is working fine except when I try to build the whole thing , it shows an error in the ui_mainwindow.h file ,

'class odometer' has no member named 'setText'

I havent used this function anywhere but qt always puts it in the ui_mainwindow.h file whenever I try to build.Please help me out, here's odometer:

odometer.h:

    #ifndef ODOMETER_H
    #define ODOMETER_H
    #include <QWidget>
    #include<QLabel>




class odometer : public QWidget
{
    Q_OBJECT

public:
    QPixmap *img = new QPixmap;
    int val1;
   void getpos(int *val);

  odometer(QWidget *parent=nullptr);

    virtual ~odometer()

    {};


protected:
    void paintEvent(QPaintEvent *event) ;
};


#endif // ODOMETER_H

odometer.cpp:

#include <QtGui>
#include <odometer.h>
#include <math.h>



odometer::odometer(QWidget *parent)
    :QWidget(parent)
{
    img->load("C:/meter.png");
}

void odometer::getpos(int *val)
{
    val1=*val;
    this->update();
}

void odometer::paintEvent(QPaintEvent *)
{

    QPointF pts[3] = {
        QPointF(-5,80),
        QPointF(5,80),
        QPointF(90*qCos(2.0944+(0.017*val1)),90*qSin(2.0944+(0.017*val1)))
        //QPointF(0,0)

};
  QPainter paint(this);

          paint.translate(200,180);
        QColor minuteColor(0, 127, 127, 191);
       paint.setRenderHint(QPainter::Antialiasing);
        paint.setPen(Qt::blue);
        paint.setBrush(minuteColor);


       paint.save();

        paint.drawConvexPolygon(pts , 3);
        paint.drawPixmap(-200,-180,400,400,*img);
        paint.restore();

}
question from:https://stackoverflow.com/questions/65843548/no-member-named-settext-error-in-qt-custom-class

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...