Answer the question
In order to leave comments, you need to log in
Why did these errors appear?
I am making a simple application in qt, it uses a graphics scene and a button. When the button is pressed, a rectangle should appear in the graphics scene.
But for some reason, errors occur on startup:
C:\Users\123\Documents\paint3\main.cpp:-1: error: undefined reference to `vtable for Paint'
:-1: error: collect2.exe: error: ld returned 1 exit status
:-1: error: [Makefile.Debug:71: debug/paint3.exe] Error
Program files themselves:
#pragma once
#include <QWidget>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QRectF>
#include <QPushButton>
#include <QGraphicsItem>
class Paint : public QWidget
{
Q_OBJECT
public:
Paint(QWidget *parent = 0);
QGraphicsScene *scene;
QGraphicsView *view;
QPushButton *btn;
private slots:
void Draw();
};
#include "paint.h"
#include <QtWidgets>
#include <QPushButton>
#include <QGraphicsItem>
Paint::Paint(QWidget *parent):QWidget(parent)
{
scene = new QGraphicsScene(QRectF(10,10,1000,1000));
view = new QGraphicsView(scene, this);
view->show();
btn = new QPushButton("Draw!", this);
btn -> setGeometry(1020, 10, 70, 30);
connect(btn, SIGNAL(clicked()), this, SLOT(Draw()));
}
void Paint::Draw()
{
QGraphicsRectItem *pRectItem = scene->addRect(QRectF(30,30, 120, 80), QPen(Qt::yellow), QBrush(Qt::green));
pRectItem ->setFlags(QGraphicsItem::ItemIsMovable);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question