[英]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.