#include "mainwindow.h" #include <QMenuBar> #include <QInputDialog> #include…
- User
#include "mainwindow.h" #include #include #include #include #include #include #include #include
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setWindowTitle("QT-GI-15");
// Создание QGraphicsView для отображения scene = new QGraphicsScene(); QGraphicsItem *item = new QGraphicsRectItem(); scene->addItem(item); view = new QGraphicsView(scene); setCentralWidget(view);
// Создание меню с действиями QMenu *fileMenu = new QMenu("File"); showPictureAction = new QAction("Show picture"); connect(showPictureAction, &QAction::triggered, this, &MainWindow::showPicture); fileMenu->addAction(showPictureAction);
chooseAction = new QAction("Choose"); connect(chooseAction, &QAction::triggered, this, &MainWindow::choose); fileMenu->addAction(chooseAction);
animateAction = new QAction("Animate"); connect(animateAction, &QAction::triggered, this, &MainWindow::animate); fileMenu->addAction(animateAction);
stopAction = new QAction("Stop"); connect(stopAction, &QAction::triggered, this, &MainWindow::stop); fileMenu->addAction(stopAction);
quitAction = new QAction("Quit"); connect(quitAction, &QAction::triggered, this, &MainWindow::quit); fileMenu->addAction(quitAction);
menuBar()->addMenu(fileMenu);
// Создание окна выбора chooseDialog = new QDialog(); chooseDialog->setWindowTitle("Choose"); speedLabel = new QLabel("Speed:"); directionLabel = new QLabel("Direction:"); upDownRadioButton = new QRadioButton("Up-Down"); leftRightRadioButton = new QRadioButton("Left-Right"); speedLineEdit = new QLineEdit(); QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(buttonBox, &QDialogButtonBox::accepted, chooseDialog, &QDialog::accept); connect(buttonBox, &QDialogButtonBox::rejected, chooseDialog, &QDialog::reject); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(speedLabel); layout->addWidget(speedLineEdit); layout->addWidget(directionLabel); layout->addWidget(upDownRadioButton); layout->addWidget(leftRightRadioButton); layout->addWidget(buttonBox); chooseDialog->setLayout(layout); }
MainWindow::~MainWindow() { delete chooseDialog; delete scene; delete view; }
void MainWindow::showPicture() { // Очистка сцены и создание объекта для отображения scene->clear();
QBrush brush(Qt::red); QPen blackpen(Qt::black); blackpen.setWidth(2); QGraphicsRectItem *rect = new QGraphicsRectItem(-50, -25, 100, 50); rect->setBrush(brush); rect->setPen(blackpen); QGraphicsEllipseItem *ellipse = new QGraphicsEllipseItem(-30, -20, 60, 40); ellipse->setBrush(brush); ellipse->setPen(blackpen); QPolygonF triangle; triangle << QPointF(0, -25) << QPointF(-25, 25) << QPointF(25, 25); QGraphicsPolygonItem *polygon = new QGraphicsPolygonItem(triangle); polygon->setBrush(brush); polygon->setPen(blackpen);
QVector trapeziumPoints; trapeziumPoints << QPointF(-50, -25); } :-1: ошибка: mainwindow.o: in function `MainWindow::MainWindow(QWidget*)':
- Assistant
mainwindow.cpp:(.text+0x1f): undefined reference to
QGraphicsScene::QGraphicsScene(QObject*)' mainwindow.cpp:(.text+0x2d): undefined reference toQGraphicsScene::addItem(QGraphicsItem*)' mainwindow.cpp:(.text+0x4f): undefined reference toQGraphicsView::QGraphicsView(QGraphicsScene*, QWidget*)' :-1: ошибка: mainwindow.o: in functionMainWindow::~MainWindow()': mainwindow.cpp:(.text+0x89): undefined reference to QGraphicsView::~QGraphicsView()' :-1: ошибка: mainwindow.o: in function QGraphicsScene::clear()' mainwindow.cpp:(.text+0x120): undefined reference to QGraphicsRectItem::setBrush(QBrush const&)' mainwindow.cpp:(.text+0x147): undefined reference to QGraphicsEllipseItem::QGraphicsEllipseItem(qreal, qreal, qreal, qreal, QGraphicsItem*)' mainwindow.cpp:(.text+0x172): undefined reference to QGraphicsEllipseItem::setPen(QPen const&)' mainwindow.cpp:(.text+0x192): undefined reference to QGraphicsPolygonItem::setBrush(QBrush const&)' mainwindow.cpp:(.text+0x1bb): undefined reference to QVector::QVector(QVector const&)' mainwindow.cpp:(.text+0x255): undefined reference to QGraphicsPolygonItem::setBrush(QBrush const&)' mainwindow.cpp:(.text+0x273): undefined reference to `QGraphicsPolygonItem::setPen(QPen const&)' :-1: ошибка: collect2: error: ld returned 1 exit status.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.