简体   繁体   中英

visual studio 2013 mysterious C2228 error

I have recently upgraded some qt projects from vs 2008 to 2013. I am getting a weird

Error   1   error C2228: left of '.currentText' must have class/struct/union    

error when I try access a combo box in my gui.

Here is the code, pretty straight forward:

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

and here is the 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!!!

}

The error I cited above comes at lines 51 and 60, where I try to access ui .

So in the constructor, the compiler is fine with the variable ui , but not in the other methods. This is pretty boiler plate qt stuff, so I'm not sure what the issue is, but, I suspect there is some flag in VS that is somehow obscuring the scope of my ui variable. All my other private variables are ok, so I don't know what the issue is.

I am sure the uic/moc process is working properly and I have tried cleaning and rebuilding to no avail.

Replace the lines:

if (!it->description().compare(ui->cameraBox.currentText()))
std::cout << ui->cameraBox.currentText() << std::endl;

By:

if (!it->description().compare(ui->cameraBox->currentText()))
std::cout << ui->cameraBox->currentText() << std::endl;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM