请在标记为已经回答之前仔细阅读,因为没有其他解决方案对我有帮助。
所以当我在调试或发布中编译我的程序时,我遇到了2个错误:
moc_guiitemlistrepeat.obj:-1: error: LNK2005: "public: void __cdecl GUIItemListRepeat::isUpdated(void)" (?isUpdated@GUIItemListRepeat@@QEAAXXZ) already defined in guiitemlistrepeat.obj
release\Calendar.exe:-1: error: LNK1169: one or more multiply defined symbols found
他们在调试时突然出现了,我不知道出了什么问题,因为据我所知,我没有编辑过那个文件。
头:
#ifndef GUIITEMLISTREPEAT_H
#define GUIITEMLISTREPEAT_H
#include <QtWidgets>
#include "appointmentrepeat.h"
class GUIItemListRepeat : public QFrame
{
Q_OBJECT
public:
GUIItemListRepeat(AppointmentRepeat *appointment);
~GUIItemListRepeat();
AppointmentRepeat* getItem();
signals:
void isUpdated();
void showDetails(AppointmentRepeat *todo);
void remove(GUIItemListRepeat *item);
private slots:
void showClicked();
void deleteClicked();
private:
AppointmentRepeat *m_repeat;
QLabel *m_title, *m_type, *m_begin, *m_end;
QPushButton *m_show, *m_delete;
};
#endif // GUIITEMLISTREPEAT_H
来源:
#include "guiitemlistrepeat.h"
GUIItemListRepeat::GUIItemListRepeat(AppointmentRepeat *appointment)
{
m_repeat = appointment;
connect(appointment, SIGNAL(updated()), this, SLOT(isUpdated()));
m_title = new QLabel(m_repeat->getTitle());
m_begin = new QLabel(m_repeat->getStart().toString(QString("hh:mm")));
m_end = new QLabel(m_repeat->getEnd().toString(QString("hh:mm")));
m_show = new QPushButton(QString("Show"));
m_delete = new QPushButton(QString("Delete"));
QString type;
if (m_repeat->getType() == DAILY)
type = tr("Dagelijks");
else if (m_repeat->getType() == WEEKLY)
type = tr("Wekelijks(%1)").arg(m_repeat->getDate().toString(tr("ddd")));
else if (m_repeat->getType() == MONTHLY)
type = tr("Maandelijks(%1)").arg(m_repeat->getDate().toString(tr("dd")));
else
type = tr("Jaarlijks(%1)").arg(m_repeat->getDate().toString(tr("dd/MM")));
m_type = new QLabel(type);
connect(m_show, SIGNAL(clicked()), this, SLOT(showClicked()));
connect(m_delete, SIGNAL(clicked()), this, SLOT(deleteClicked()));
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(m_type, 0, 0);
mainLayout->addWidget(m_begin, 1, 0);
mainLayout->addWidget(m_end, 2, 0);
mainLayout->addWidget(m_title, 0, 1, 1, 2);
mainLayout->addWidget(m_show, 1, 1);
mainLayout->addWidget(m_delete, 1, 2);
setLayout(mainLayout);
setFrameShape(QFrame::Box);
setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
}
GUIItemListRepeat::~GUIItemListRepeat()
{
delete m_title;
delete m_type;
delete m_begin;
delete m_end;
delete m_show;
delete m_delete;
}
AppointmentRepeat* GUIItemListRepeat::getItem()
{
return m_repeat;
}
void GUIItemListRepeat::showClicked()
{
emit showDetails(m_repeat);
}
void GUIItemListRepeat::deleteClicked()
{
emit remove(this);
}
void GUIItemListRepeat::isUpdated()
{
m_title->setText(m_repeat->getTitle());
m_begin->setText(m_repeat->getStart().toString(QString("hh:mm")));
m_end->setText(m_repeat->getEnd().toString(QString("hh:mm")));
if (m_repeat->getType() == DAILY)
m_type->setText(tr("Dagelijks"));
else if (m_repeat->getType() == WEEKLY)
m_type->setText(tr("Wekelijks(%1)").arg(m_repeat->getDate().toString(tr("ddd"))));
else if (m_repeat->getType() == MONTHLY)
m_type->setText(tr("Maandelijks(%1)").arg(m_repeat->getDate().toString(tr("dd"))));
else
m_type->setText(tr("Jaarlijks(%1)").arg(m_repeat->getDate().toString(tr("dd/MM"))));
}
如果我能得到这个问题的答案,那真的会对我有所帮助,因为我真的完全陷入绝望之中:(
PS:是否可以执行以下操作:找不到文件:moc_guiitemlistrepeat.obj?
编辑:如果这可以帮到你这里
moc_guiitemlistrepeat.obj https://dl.dropboxusercontent.com/u/110311126/moc_guiitemlistrepeat.obj
moc_guiitemlistrepeat.cpp https://dl.dropboxusercontent.com/u/110311126/moc_guiitemlistrepeat.cpp
答案 0 :(得分:2)
问题在于您将isUpdated()
函数声明为信号,但请将其用作班级中的插槽。因此,您有两个相同函数的定义:一个在moc_guiitemlistrepeat.cpp
文件中(由qmake生成),另一个是void GUIItemListRepeat::isUpdated()
定义由您自己编写。
要解决此问题,您只需将isUpdated()
声明为插槽。