简体   繁体   English

未声明的标识符(包括头文件)

[英]Undeclared Identifier (header file included)

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QStandardItemModel>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow{
    Q_OBJECT
public:
    Ui::MainWindow *ui;
    QList<QStringList> csv;
    QStandardItemModel *model;
    QList<QStandardItem*> standardItemList;
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
    void on_action_Open_triggered();
    void checkString(QString &temp, QChar ch = 0);
};

#endif // MAINWINDOW_H

maindwindow.cpp maindwindow.cpp

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
#include <QDebug>

MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QObject::connect(ui->Open, SIGNAL(clicked()),
                     this,SLOT(on_action_Open_triggered()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_action_Open_triggered()
{

    model = new QStandardItemModel(this);
    ui->tableView->setModel(model);

    QString fileName = QFileDialog::getOpenFileName(this, "Open CSV file",QDir::currentPath(), "csv (*.csv)");
    QFile file(fileName);

    if (file.open(QIODevice::ReadOnly))
    {

        QString data = file.readAll();
        data.remove(QRegExp("\r")); // remove all carriage return characters
        QString temp;
        QChar ch;
        QTextStream instream (&data);

        while (!instream.atEnd())
        {
            instream >> ch;
            if (ch == ',')
                checkString(temp, ch);
            else if (ch == '\n')
                checkString(temp, ch);
            else if (instream.atEnd())
            {
                temp.append(ch);
                checkString(temp);
            } else
                temp.append(ch);
        }
    }
}

void MainWindow::checkString(QString &temp, QChar ch)
{

    if (temp.count("\"")%2 == 0)
    {
        if (temp.startsWith(QChar('\"')) && temp.endsWith(QChar('\"')))
        {
            temp.remove(QRegExp("^\""));
            temp.remove(QRegExp("\"$"));
        }

        temp.replace("\"\"", "\"");
        QStandardItem *item = new QStandardItem(temp);
        standardItemList.append(item);

        if (ch != QChar(','))
        {
        }

        temp.clear();
    } else
        temp.append(ch);
}

void something()
{
    qDebug() << standardItemList;
}

I am being told standardItemList, undeclared identifier in the something function(why not in the checkstring function?). 有人告诉我standardItemList,在some函数中的未声明标识符(为什么不在checkstring函数中?)。 However I have included mainwindow.h and that includes a definition of standardItemList. 但是,我包含了mainwindow.h,其中包括standardItemList的定义。 does it have something to do with the standardItemList containing *item and that is declared within checkString 它与包含* item并在checkString中声明的standardItemList有关系吗?

#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QFile>
#include <QFileDialog>
#include <QTextStream>
#include <QStandardItemModel>

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow{
    Q_OBJECT
public:
    Ui::MainWindow *ui;
    QList<QStringList> csv;
    QStandardItemModel *model;
    QList<QStandardItem*> standardItemList;
    MainWindow(QWidget *parent = 0);
    ~MainWindow();
private slots:
    void on_action_Open_triggered();
    void checkString(QString &temp, QChar ch = 0);
    void something();
};

void MainWindow::something()
{
    qDebug() << standardItemList;
}

checkString is a private member therefore you can't call it from outside the class so standardItemList is not defined. checkString是私有成员,因此您不能从类外部调用它,因此未定义standardItemList

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未声明的标识符:包括标头,不是圆形的 - undeclared identifier: header included, not circular 我收到未声明的标识符错误,但我已包含 header 文件? - I am getting an undeclared identifier error but I have included the header file? 错误:&#39;cout&#39;:未声明的标识符; 虽然我在程序中包含了iostream头文件 - Error: 'cout' : undeclared identifier; though I've included iostream header file in program 在头文件中使用未声明的标识符 (Clang) - Use of undeclared identifier in header file (Clang) 如何在我的头文件中修复(&#39;vector&#39;:未声明的标识符)? - How to fix ( 'vector' : undeclared identifier ) in my header file? 最后一个头文件错误:C2065: &#39;xxx&#39; : undeclared identifier - The last header file error: C2065: 'xxx' : undeclared identifier 类实现文件中未声明的标识符 - Undeclared identifier in class implementation file Flex 文件中的“未声明的标识符”错误 - “undeclared identifier” error in Flex file C ++主文件具有未声明的标识符,该标识符在头文件(Xcode)中声明 - C++ main file has undeclared identifier that's declared in the header file (Xcode) 未声明的标识符 - undeclared identifier
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM