我正在编写一个项目的代码。在尝试进行静态构建之后,我开始出现错误。我做了些改变,我不记得了。但是,我相信,如果这个存根可以被清除,那么主要的项目也可以被清除。
这是头文件。
#ifndef MYLABEL_H
#define MYLABEL_H
#include <QFileDialog>
#include <QLabel>
#include <QMouseEvent>
#include <QObject>
#include <QPaintEvent>
class MyLabel:public QWidget
{
private:
QPixmap default_Pixmap;
QPixmap pixmap;
QFileDialog * fileDialog;
Q_OBJECT
public:
MyLabel();
void setPixmap(QPixmap pixmap);
void setDefault();
protected:
void mousePressEvent(QMouseEvent *event);
void paintEvent(QPaintEvent * event);
signals:
void file_Selected(QString fileName);
private slots:
void file_Got_Selected(QString fileName);
};
#endif // MYLABEL_H这是源文件
#include "MyLabel.h"
#include "MyMessageBox.h"
#include <QFileDialog>
#include <QPainter>
MyLabel::MyLabel():QWidget()
{
default_Pixmap = QPixmap("select.gif").scaled(250,100);
this->fileDialog=new QFileDialog(this);
fileDialog->setNameFilter("Image Files (*.BMP *.GIF *.JPG *.JPEG *.PNG *.PBM *.PGM *.PPM *.XBM *.XPM)");
connect(fileDialog,SIGNAL(fileSelected(QString)),this,SIGNAL(file_Selected(QString)));
connect(fileDialog,SIGNAL(fileSelected(QString)),this,SLOT(file_Got_Selected(QString)));
}
void MyLabel::setPixmap(QPixmap pixmap)
{
this->pixmap = pixmap;
}
void MyLabel::setDefault()
{
this->pixmap = default_Pixmap;
}
void MyLabel::mousePressEvent(QMouseEvent *event)
{
fileDialog->show();
//QString file_Name = file_Dialog.getOpenFileName();
}
void MyLabel::paintEvent(QPaintEvent * event)
{
QPainter painter(this);
painter.drawPixmap(0,0,width(),height(),pixmap.scaled(QSize(width(),height())));
}
void MyLabel::file_Got_Selected(QString fileName)
{
this->pixmap = QPixmap(fileName);
}
#include "myLabel.moc"这是主要文件
#include <QLabel>
#include <QPixmap>
#include <QtGui/QApplication>
#include "myLabel.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyLabel mm;
//mm.setPixmap(QPixmap("dummy.jpg"));
//mm.setPixmap(QPixmap());
mm.setDefault();
mm.show();
return a.exec();
}我使用qt命令提示符和命令创建moc文件。
moc myLabel.h -o myLabel.moc在此之后,我尝试通过Qt-Editor编译该项目。但我发现了以下多个定义错误,
debug/moc_myLabel.o:d:/TempInstallationFolder/Qt/Dynamic/qt/include/QtCore/../../src/corelib/global/qglobal.h:1381: multiple definition of `MyLabel::metaObject() const'调试/myLabel.o:C:\Documents和Settings\prabhakaran\Desktop\CalendarNew-build-desktop/../CalendarNew//myLabel.moc:57:首先在这里定义
调试/moc_myLabel.o:C:\`MyLabel::qt_metacast的多个定义(const*)
调试/myLabel.o:C:\Documents和Settings\prabhakaran\Desktop\CalendarNew-build-desktop/../CalendarNew//myLabel.moc:62:首先在这里定义
调试/moc_myLabel.o:C:\`MyLabel::qt_metacall的多个定义(QMetaObject::Call,int,void**)‘
调试/myLabel.o:C:\Documents和Settings\prabhakaran\Desktop\CalendarNew-build-desktop/../CalendarNew//myLabel.moc:70:首先在这里定义
调试/moc_myLabel.o:C:\Documents和Settings\prabhakaran\Desktop\CalendarNew-build-desktop/debug/moc_myLabel.cpp:87:`MyLabel::file_Selected(QString)的多重定义
调试/myLabel.o:C:\Documents和Settings\prabhakaran\Desktop\CalendarNew-build-desktop/../CalendarNew//myLabel.moc:87:首先在这里定义
“`MyLabel::staticMetaObject”的debug/moc_myLabel.o:moc_myLabel.cpp:(.data+0x0):多重定义
调试/myLabel.o:myLabel.cpp:(.data+0x0):这里首先定义
collect2: ld返回1个退出状态
Make1:* debug\CalendarNew.exe错误1
mingw32-make:*调试错误2
进程"D:/TempInstallationFolder/Qt/Dynamic/mingw/bin/mingw32-make.exe“以代码%2退出。在执行生成步骤'Make‘时生成项目CalendarNew (目标:桌面)时出错
任何人都请帮我解决这个问题。
发布于 2011-05-08 07:04:29
尝试删除源文件中的行include "MyLabel.moc"。您不需要将它包含到cpp文件中。
https://stackoverflow.com/questions/5926038
复制相似问题