我正在尝试连接信号。但我继续遇到这个。我确信我已经链接了包含QAction * actionCameraSetup的* .h文件。我错过了什么吗?
请帮忙。 感谢。
错误:
1> camera.cpp 1>。\ camera.cpp(10):错误C2065:'actionCamera_Setup': 未声明的标识符
camera.cpp
#include "camera.h"
#include "camera_setup.h"
#include "ui_camera.h"
Camera::Camera(QWidget *parent, Qt::WFlags flags)
: QMainWindow(parent, flags)
{
ui.setupUi(this);
connect(actionCamera_Setup, SIGNAL(activated()), this, SLOT(openCameraSetup()));
}
Camera::~Camera()
{
}
void Camera::openCameraSetup()
{
newCameraSetup = new camera_setup();
newCameraSetup->show();
}
camera.h
#ifndef CAMERA_H
#define CAMERA_H
#include <QtGui/QMainWindow>
#include "ui_camera.h"
#include "ui_camera_setup.h"
class camera_setup;
class Camera : public QMainWindow
{
Q_OBJECT
public:
Camera(QWidget *parent = 0, Qt::WFlags flags = 0);
~Camera();
public slots:
void openCameraSetup();
private:
Ui::CameraClass ui;
camera_setup *newCameraSetup;
};
#endif // CAMERA_H
ui_camera.h
#ifndef UI_CAMERA_H
#define UI_CAMERA_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QGridLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QMenu>
#include <QtGui/QMenuBar>
#include <QtGui/QWidget>
class QAction;
QT_BEGIN_NAMESPACE
class Ui_CameraClass
{
public:
QAction *actionExit;
QAction *actionCamera_Setup;
QAction *actionFull_Screen;
QAction *action1_Camera_1;
QAction *action1_Camera_2;
QAction *action1_Camera_3;
QAction *action1_Camera_4;
QAction *action1_Camera_5;
QAction *action1_Camera_6;
QAction *action2_Camera_1;
QAction *action2_Camera_2;
QAction *action2_Camera_3;
QAction *action2_Camera_4;
QAction *action2_Camera_5;
QAction *action2_Camera_6;
QWidget *centralWidget;
QGridLayout *gridLayout;
QLabel *label_CCV;
QMenuBar *menuBar;
QMenu *menuFile;
QMenu *menuView;
QMenu *menuCameras;
void setupUi(QMainWindow *CameraClass)
{
if (CameraClass->objectName().isEmpty())
CameraClass->setObjectName(QString::fromUtf8("CameraClass"));
CameraClass->resize(600, 367);
actionExit = new QAction(CameraClass);
actionExit->setObjectName(QString::fromUtf8("actionExit"));
actionCamera_Setup = new QAction(CameraClass);
actionCamera_Setup->setObjectName(QString::fromUtf8("actionCamera_Setup"));
actionFull_Screen = new QAction(CameraClass);
actionFull_Screen->setObjectName(QString::fromUtf8("actionFull_Screen"));
action1_Camera_1 = new QAction(CameraClass);
action1_Camera_1->setObjectName(QString::fromUtf8("action1_Camera_1"));
action1_Camera_2 = new QAction(CameraClass);
action1_Camera_2->setObjectName(QString::fromUtf8("action1_Camera_2"));
action1_Camera_3 = new QAction(CameraClass);
action1_Camera_3->setObjectName(QString::fromUtf8("action1_Camera_3"));
action1_Camera_4 = new QAction(CameraClass);
action1_Camera_4->setObjectName(QString::fromUtf8("action1_Camera_4"));
action1_Camera_5 = new QAction(CameraClass);
action1_Camera_5->setObjectName(QString::fromUtf8("action1_Camera_5"));
action1_Camera_6 = new QAction(CameraClass);
action1_Camera_6->setObjectName(QString::fromUtf8("action1_Camera_6"));
action2_Camera_1 = new QAction(CameraClass);
action2_Camera_1->setObjectName(QString::fromUtf8("action2_Camera_1"));
action2_Camera_2 = new QAction(CameraClass);
action2_Camera_2->setObjectName(QString::fromUtf8("action2_Camera_2"));
action2_Camera_3 = new QAction(CameraClass);
action2_Camera_3->setObjectName(QString::fromUtf8("action2_Camera_3"));
action2_Camera_4 = new QAction(CameraClass);
action2_Camera_4->setObjectName(QString::fromUtf8("action2_Camera_4"));
action2_Camera_5 = new QAction(CameraClass);
action2_Camera_5->setObjectName(QString::fromUtf8("action2_Camera_5"));
action2_Camera_6 = new QAction(CameraClass);
action2_Camera_6->setObjectName(QString::fromUtf8("action2_Camera_6"));
centralWidget = new QWidget(CameraClass);
centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
gridLayout = new QGridLayout(centralWidget);
gridLayout->setSpacing(0);
gridLayout->setContentsMargins(0, 0, 0, 0);
gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
label_CCV = new QLabel(centralWidget);
label_CCV->setObjectName(QString::fromUtf8("label_CCV"));
gridLayout->addWidget(label_CCV, 0, 0, 1, 1);
CameraClass->setCentralWidget(centralWidget);
menuBar = new QMenuBar(CameraClass);
menuBar->setObjectName(QString::fromUtf8("menuBar"));
menuBar->setGeometry(QRect(0, 0, 600, 21));
menuFile = new QMenu(menuBar);
menuFile->setObjectName(QString::fromUtf8("menuFile"));
menuView = new QMenu(menuBar);
menuView->setObjectName(QString::fromUtf8("menuView"));
menuCameras = new QMenu(menuView);
menuCameras->setObjectName(QString::fromUtf8("menuCameras"));
CameraClass->setMenuBar(menuBar);
menuBar->addAction(menuFile->menuAction());
menuBar->addAction(menuView->menuAction());
menuFile->addAction(actionExit);
menuView->addAction(menuCameras->menuAction());
menuView->addAction(actionCamera_Setup);
menuView->addSeparator();
menuView->addAction(actionFull_Screen);
menuCameras->addAction(action1_Camera_1);
menuCameras->addAction(action1_Camera_2);
menuCameras->addAction(action1_Camera_3);
menuCameras->addAction(action1_Camera_4);
menuCameras->addAction(action1_Camera_5);
menuCameras->addAction(action1_Camera_6);
menuCameras->addSeparator();
menuCameras->addAction(action2_Camera_1);
menuCameras->addAction(action2_Camera_2);
menuCameras->addAction(action2_Camera_3);
menuCameras->addAction(action2_Camera_4);
menuCameras->addAction(action2_Camera_5);
menuCameras->addAction(action2_Camera_6);
retranslateUi(CameraClass);
QObject::connect(actionCamera_Setup, SIGNAL(activated()), CameraClass, SLOT(show()));
QMetaObject::connectSlotsByName(CameraClass);
} // setupUi
void retranslateUi(QMainWindow *CameraClass)
{
CameraClass->setWindowTitle(QApplication::translate("CameraClass", "Camera", 0, QApplication::UnicodeUTF8));
actionExit->setText(QApplication::translate("CameraClass", "Exit", 0, QApplication::UnicodeUTF8));
actionCamera_Setup->setText(QApplication::translate("CameraClass", "Camera Setup", 0, QApplication::UnicodeUTF8));
actionFull_Screen->setText(QApplication::translate("CameraClass", "Full Screen", 0, QApplication::UnicodeUTF8));
action1_Camera_1->setText(QApplication::translate("CameraClass", "1 Camera 1", 0, QApplication::UnicodeUTF8));
action1_Camera_2->setText(QApplication::translate("CameraClass", "1 Camera 2", 0, QApplication::UnicodeUTF8));
action1_Camera_3->setText(QApplication::translate("CameraClass", "1 Camera 3", 0, QApplication::UnicodeUTF8));
action1_Camera_4->setText(QApplication::translate("CameraClass", "1 Camera 4", 0, QApplication::UnicodeUTF8));
action1_Camera_5->setText(QApplication::translate("CameraClass", "1 Camera 5", 0, QApplication::UnicodeUTF8));
action1_Camera_6->setText(QApplication::translate("CameraClass", "1 Camera 6", 0, QApplication::UnicodeUTF8));
action2_Camera_1->setText(QApplication::translate("CameraClass", "2 Camera 1", 0, QApplication::UnicodeUTF8));
action2_Camera_2->setText(QApplication::translate("CameraClass", "2 Camera 2", 0, QApplication::UnicodeUTF8));
action2_Camera_3->setText(QApplication::translate("CameraClass", "2 Camera 3", 0, QApplication::UnicodeUTF8));
action2_Camera_4->setText(QApplication::translate("CameraClass", "2 Camera 4", 0, QApplication::UnicodeUTF8));
action2_Camera_5->setText(QApplication::translate("CameraClass", "2 Camera 5", 0, QApplication::UnicodeUTF8));
action2_Camera_6->setText(QApplication::translate("CameraClass", "2 Camera 6", 0, QApplication::UnicodeUTF8));
label_CCV->setText(QApplication::translate("CameraClass", "<html><head/><body><p><img src=\":/Camera/Resources/pictures/Camera View.jpg\"/></p></body></html>", 0, QApplication::UnicodeUTF8));
menuFile->setTitle(QApplication::translate("CameraClass", "File", 0, QApplication::UnicodeUTF8));
menuView->setTitle(QApplication::translate("CameraClass", "View", 0, QApplication::UnicodeUTF8));
menuCameras->setTitle(QApplication::translate("CameraClass", "Cameras...", 0, QApplication::UnicodeUTF8));
} // retranslateUi
};
namespace Ui {
class CameraClass: public Ui_CameraClass {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_CAMERA_H
答案 0 :(得分:0)
actionCamera_Setup
是类Ui::CameraClass
的属性。在C ++中,只有当属性是同一类代码所属的属性时,才能按名称访问属性,否则,应通过对象实例或指向对象实例的指针访问属性
instanceOfClassName.propertyName
或
pointerToInstanceOfClassName->propertyName
在您的情况下,instanceOfClassName
为ui
,因为Ui::CameraClass ui
类中定义了属性Camera
。