我有一个问题 - 之前讨论过很多,但我看到的所有解决方案在这里都不起作用。这段代码有什么问题?
main.cpp:8:19: error: invalid use of ‘this’ in non-member function
#include <QApplication>
#include <QPainter>
#include <math.h>
class QPainter;
int main(int argc, char *argv[]){
QApplication app(argc,argv);
QPainter painter(this);
painter.setPen(QPen(Qt::black,3));
int n=8;
for (int i=0;i<n;++i){
qreal fAngle=2*3.14*i/n;
qreal x = 50 + cos(fAngle)*40;
qreal y = 50 + sin(fAngle)*40;
painter.drawPoint(QPointF(x,y));
}
return app.exec();
}