Answer the question
In order to leave comments, you need to log in
Can't run code?
main.cpp
#include <iostream>
#include <QtWidgets/QApplication>
#include "MainWindow.h"
int main(int argc,char*argv[])
{
QApplication a(argc, argv);
MainWindow mw;
return a.exec();
}
#pragma once
#include <QtWidgets/qmainwindow.h>
#include <QtGui/qpicture.h>
#include <QtGui/qimage.h>
#include <QtGui/qpainter.h>
#pragma comment(lib,"Qt5Core.lib")
#pragma comment(lib,"Qt5Widgets.lib")
#pragma comment(lib,"Qt5Gui.lib")
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget* parent = 0);
~MainWindow();
protected:
void paintEvent(QPaintEvent*); // пееопределение виртуальной функции
private:
Ui::MainWindow* ui;
};
#include "MainWindow.h"
void MainWindow::paintEvent(QPaintEvent*)
{
QImage img("sea.png"); // загружаем картинку
QPainter painter(this); // определяем объект painter, который обеспечивает рисование
painter.drawImage(0, 0, img.scaled(this->size())); // рисуем наше изображение от 0,0 и растягиваем по всему виджету
}
Ошибка LNK2001 неразрешенный внешний символ "public: virtual __cdecl MainWindow::~MainWindow(void)" ([email protected]@[email protected]).
и
Ошибка LNK2001 неразрешенный внешний символ "public: __cdecl MainWindow::MainWindow(class QWidget *)" ([email protected]@[email protected]@@@Z).
Answer the question
In order to leave comments, you need to log in
I commented out the header in the QOBJECT class and the destructor, added the constructor implementation to MainWindow.cpp:
MainWindow::MainWindow(QWidget* parent)
: QMainWindow(parent)
{
setWindowTitle(tr("Window"));
setGeometry(0, 0, 1000, 700);
}
#include <iostream>
#include <QtWidgets/QApplication>
#include "MainWindow.h"
#pragma comment(lib,"Qt5Widgets.lib")
int main(int argc,char*argv[])
{
QApplication a(argc, argv);
QWidget qw;
//qw.show();
MainWindow mw(&qw);
mw.show();
return a.exec();
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question