我最近将一些qt项目从vs 2008升级到2013.我得到了一个奇怪的
Error 1 error C2228: left of '.currentText' must have class/struct/union
当我尝试访问我的gui中的组合框时出现错误。
这是代码,很简单:
videopanel.h
#ifndef VIDEOPANEL_H
#define VIDEOPANEL_H
#include <QCamera>
#include <QtWidgets>
#include <QMediaRecorder>
#include <QCameraImageCapture>
#include <QCameraViewFinder>
#include <QVideoWidget>
namespace Ui {
class videoPanel;
}
class videoPanel : public QWidget
{
Q_OBJECT
public:
explicit videoPanel(QWidget *parent = 0);
~videoPanel();
private slots:
void monitorToggle(int state);
private:
Ui::videoPanel *ui;
QCamera *camera;
QList<QCameraInfo> cameraInfos;
QCameraImageCapture *imageCapture;
QMediaRecorder* mediaRecorder;
QImageEncoderSettings imageSettings;
QAudioEncoderSettings audioSettings;
QVideoEncoderSettings videoSettings;
QString videoContainerFormat;
bool isCapturingVideo;
void setCamera(void);
};
#endif // VIDEOPANEL_H
这里是cpp: videopanel.cpp
#include "videopanel.h"
#include "ui_videopanel.h"
#include <QMediaService>
#include <QMediaRecorder>
#include <QCameraViewfinder>
#include <QCameraInfo>
#include <QMediaMetaData>
#include <iostream>
videoPanel::videoPanel(QWidget *parent) :
QWidget(parent),
ui(new Ui::videoPanel),
camera(0),
imageCapture(0),
mediaRecorder(0)
{
ui->setupUi(this); // fine!!!
QObject::connect(ui->monitorCheck, SIGNAL(stateChanged(int)), this, SLOT(monitorToggle(int)) );
// Camera devices:
cameraInfos = QCameraInfo::availableCameras();
// display device descriptions in combo box
for (QList<QCameraInfo>::Iterator it = cameraInfos.begin();
it != cameraInfos.end(); ++it)
ui->cameraBox->addItem(it->description()); // fine!!!
}
videoPanel::~videoPanel()
{
delete mediaRecorder;
delete imageCapture;
delete camera;
}
void videoPanel::setCamera(void) {
delete imageCapture;
delete mediaRecorder;
delete camera;
for (QList<QCameraInfo>::Iterator it = cameraInfos.begin();
it != cameraInfos.end(); ++it)
if (!it->description().compare(ui->cameraBox.currentText())) // not fine!!!
camera = new QCamera(*it);
}
void videoPanel::monitorToggle(int state) {
if (state == Qt::CheckState::Checked);
std::cout << ui->cameraBox.currentText() << std::endl; // not fine!!!
}
我上面引用的错误来自第51和第60行,我尝试访问ui
。
因此在构造函数中,编译器可以使用变量ui
,但在其他方法中则不行。这是非常好的锅炉问题,所以我不确定问题是什么,但是,我怀疑VS中有一些标志会以某种方式模糊我的ui
变量的范围。我所有其他私有变量都没问题,所以我不知道是什么问题。
我确信uic/moc
进程正常运行,我尝试过清理和重建无效。
答案 0 :(得分:0)
替换行:
if (!it->description().compare(ui->cameraBox.currentText()))
std::cout << ui->cameraBox.currentText() << std::endl;
人:
if (!it->description().compare(ui->cameraBox->currentText()))
std::cout << ui->cameraBox->currentText() << std::endl;