【发布时间】:2011-11-17 20:43:05
【问题描述】:
我正在 Qt 中创建一个应用程序 我得到一个编译错误:错误 C2065:'callDialog':未声明的标识符 在我的 CategoryDialog 类中 错误行:
CallDialog* callDialog = ((CallDialog*)dialogStack->widget(1));
CategoryDialog 类的倒数第五行:
#include "ui_categorydialog_new.h"
#include "calldialog.h"
#include "questionsdialog.h"
#include "../objects/call.h"
#include "../webservice/dataconnector.h"
#include "../webservice/dataconngetter.h"
namespace Ui {
class CategoryDialog;
}
class CategoryDialog : public QDialog
{
Q_OBJECT
public:
explicit CategoryDialog(QWidget *parent = 0) : QDialog(parent), ui(new Ui::CategoryDialog){
ui->setupUi(this);
}
~CategoryDialog()
{
delete ui;
}
private slots:
void on_btn_back_clicked()
{
ui->btn_back->setEnabled(false);
DataConnGetter::getConnector()->setCallAbort(call->getId()); //get errormessage back and show errormessage when nessesary
QStackedWidget* dialogStack = (QStackedWidget*)this->parentWidget();
CallDialog* callDialog = ((CallDialog*)dialogStack->widget(1)); //TODO 005 replace indexes with enums > more clear
callDialog->updateCalls(false);
dialogStack->setCurrentIndex(1);
ui->btn_back->setEnabled(true);
}
CallDialog 类如下所示
#include <QDialog>
#include <QString>
#include <QList>
#include <QSound>
#include <QtDebug>
#include <QStringList>
#include <QPushButton>
#include <QStackedWidget>
#include <QtAlgorithms>
#include <QLabel>
#include <typeinfo>
#include "ui_calldialog.h"
#include "callbutton.h"
#include "categorydialog_new.h"
#include "../settings/consts.h"
#include "../webservice/dataconnector.h"
#include "../webservice/dataconngetter.h"
#include "../settings/programsettings.h"
#include "../webservice/pollingservice.h"
class PollingService;
namespace Ui {
class CallDialog;
}
class CallDialog : public QDialog
{
Q_OBJECT
public:
// explicit CallDialog(QWidget *parent = 0);
// ~CallDialog();
// void initCalls();
// void updateCalls(bool sound);
// void enablePoller();
explicit CallDialog(QWidget *parent = 0) : QDialog(parent), ui(new Ui::CallDialog)
{
ui->setupUi(this);
installEventFilter(this);
注意正确包含在 CategoryDialog 中
它们确实相互包含(可能是循环依赖问题?) 我尝试前向声明 CallDialog。没有帮助。
这些文件只是直接在内部实现的 .h 文件
编辑
我绕过这个问题如下: 我添加了一个抽象类,其中包含 CallDialog 从 CategoryDialog 使用的函数
像这样:
#ifndef ABSTRACTDIALOG_H
#define ABSTRACTDIALOG_H
#include <QDialog>
#include "../objects/call.h"
class AbstractDialog : public QDialog
{
Q_OBJECT
public:
explicit AbstractDialog(QWidget *parent = 0) : QDialog(parent){}
void setCall(Call* call){
_call = call;
}
private:
Call* _call;
};
#endif // ABSTRACTDIALOG_H
【问题讨论】:
-
能否指出导致编译器错误的行号和文件?
-
是的,我添加了错误行(第一个代码块中的倒数第五行)
-
您能否将失败行更改为
((CallDialog*)dialogStack->widget(1))->updateCalls(false);callDialog变量在下一行仅使用一次,编译器错误抱怨callDialog,而不是CallDialog。很想知道更改后会产生什么错误,因为我没有看到代码有任何明显错误。 -
CallDialog类声明的右大括号后面是否有分号(应该有)?
-
@Berty 您能否上传编译器产生的所有错误并尽可能完成源代码。
标签: c++ compilation include declaration