这里为什么会出现重复定义的报错。我的.pro文件里没有重复出现的文件,但是个人认为代码不存在问题,urgent mission!thanks!
widget.cpp
#include "widget.h"
#include "ui_widget.h"
#include <QFileDialog>
#include <QMessageBox>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
connect(ui->pushButton_1,SIGNAL(clicked),ui->label_1,SLOT(checkpic1()));
connect(ui->pushButton_2,SIGNAL(clicked),ui->label_2,SLOT(checkpic1()));
}
Widget::~Widget()
{
delete ui;
}
QString Widget:: checkpic1()
{
QString pic1;
pic1=QFileDialog::getOpenFileName(this,
tr("选择图像"),
"",
tr("Images (*.png *.bmp *.jpg *.tif *.GIF )"));//可打开的文件类型
if(!pic1.isEmpty())
{
QImage* img=new QImage;
if(! ( img->load(pic1) ) ) //加载图像
{
QMessageBox::information(this,
tr("打开图像失败"),
tr("打开图像失败!"));
delete img;
}
ui->label->setPixmap(QPixmap::fromImage(*img));
}
return pic1;
}
QString Widget::checkpic2()
{
QString pic2;
pic2=QFileDialog::getOpenFileName(this,
tr("选择图像"),
"",
tr("Images (*.png *.bmp *.jpg *.tif *.GIF )"));//可打开的文件类型
if(!pic2.isEmpty())
{
QImage* img=new QImage;
if(! ( img->load(pic2) ) ) //加载图像
{
QMessageBox::information(this,
tr("打开图像失败"),
tr("打开图像失败!"));
delete img;
}
ui->label->setPixmap(QPixmap::fromImage(*img));
}
return pic2;
}
.pro
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++11
# The following define makes your compiler emit warnings if you use
# any Qt feature that has been marked deprecated (the exact warnings
# depend on your compiler). Please consult the documentation of the
# deprecated API in order to know how to port your code away from it.
DEFINES += QT_DEPRECATED_WARNINGS
# You can also make your code fail to compile if it uses deprecated APIs.
# In order to do so, uncomment the following line.
# You can also select to disable deprecated APIs only up to a certain version of Qt.
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
SOURCES += \
main.cpp \
widget.cpp
HEADERS += \
widget.h
FORMS += \
widget.ui
# Default rules for deployment.
qnx: target.path = /tmp/$${TARGET}/bin
else: unix:!android: target.path = /opt/$${TARGET}/bin
!isEmpty(target.path): INSTALLS += target