Linux /opt/project/Qt/spreadsheet/cell.h:0:注意:未找到相关类。没有生成输出
/opt/project/Qt/spreadsheet/cell.h:0:注意:未找到相关类。没有生成输出。 大家好,我已经在虚拟机中安装了centos6.4。我正在构建一个在“C++-GUI-Programming-with-Qt-4-1st-ed.pdf”一书中给出的项目。但在书中,它是通过编码实现的,我正在使用GUI进行构建 这是我的cell.h文件:-Linux /opt/project/Qt/spreadsheet/cell.h:0:注意:未找到相关类。没有生成输出,linux,qt,Linux,Qt,/opt/project/Qt/spreadsheet/cell.h:0:注意:未找到相关类。没有生成输出。 大家好,我已经在虚拟机中安装了centos6.4。我正在构建一个在“C++-GUI-Programming-with-Qt-4-1st-ed.pdf”一书中给出的项目。但在书中,它是通过编码实现的,我正在使用GUI进行构建 这是我的cell.h文件:- #ifndef CELL_H #define CELL_H #include <QTableWidgetItem>
#ifndef CELL_H
#define CELL_H
#include <QTableWidgetItem>
#include <QWidget>
class Cell : public QTableWidgetItem
{
public:
Cell();
QTableWidgetItem *clone() const;
void setData(int role, const QVariant &value);
QVariant data(int role) const;
void setFormula(const QString &formula);
QString formula() const;
void setDirty();
private:
QVariant value() const;
QVariant evalExpression(const QString &str, int &pos) const;
QVariant evalTerm(const QString &str, int &pos) const;
QVariant evalFactor(const QString &str, int &pos) const;
mutable QVariant cachedValue;
mutable bool cacheIsDirty;
};
#endif // CELL_H
\ifndef单元
#定义单元
#包括
#包括
类单元格:公共QTableWidgetItem
{
公众:
细胞();
QTableWidgetItem*克隆()常量;
void setData(int角色、常量变量和值);
QVariant数据(int角色)常量;
void setFormula(const QString&formula);
QString公式()常量;
void setDirty();
私人:
QVariant value()常量;
QVariant evalExpression(常量QString&str,int&pos)常量;
QVariant evalTerm(常量QString&str,int&pos)常量;
QVariant evalFactor(常量QString&str,int&pos)常量;
可变QVariant cachedValue;
可变布尔缓存密度;
};
#endif//CELL\u H
这是它的cell.cpp文件:-
#include "cell.h"
#include <QtWidgets>
Cell::Cell()
{
setDirty();
}
QTableWidgetItem *Cell::clone() const
{
return new Cell(*this);
}
void Cell::setData(int role, const QVariant &value)
{
QTableWidgetItem::setData(role, value);
if(role == Qt::EditRole)
{
setDirty();
}
}
QString Cell::formula() const
{
return data(Qt::EditRole).toString();
}
const QVariant Invalid;
QVariant Cell::data(int role) const
{
if(role == Qt::DisplayRole)
{
if(this->value().isValid())
return value().toString();
else
return "####";
}
else if(role == Qt::TextAlignmentRole)
{
if(this->value().type() == QVariant::String)
return int(Qt::AlignCenter| Qt::AlignVCenter);
else
return int(Qt::AlignRight | Qt::AlignVCenter);
}
else
{
return QTableWidgetItem::data(role);
}
}
void Cell::setFormula(const QString &formula)
{
setData(Qt::EditRole, formula);
}
void Cell::setDirty()
{
this->cacheIsDirty = true;
}
QVariant Cell::value() const
{
if (cacheIsDirty)
{
cacheIsDirty = false;
QString formulaStr = formula();
if (formulaStr.startsWith('\''))
{
cachedValue = formulaStr.mid(1);
}
else if (formulaStr.startsWith('='))
{
cachedValue = Invalid;
QString expr = formulaStr.mid(1);
expr.replace(" ", "");
expr.append(QChar::Null);
int pos = 0;
cachedValue = evalExpression(expr, pos);
if (expr[pos] != QChar::Null)
cachedValue = Invalid;
}
else
{
bool ok;
double d = formulaStr.toDouble(&ok);
if (ok)
{
cachedValue = d;
}
else
{
cachedValue = formulaStr;
}
}
}
return cachedValue;
}
QVariant Cell::evalExpression(const QString &str, int &pos) const
{
QVariant result = evalTerm(str, pos);
while (str[pos] != QChar::Null)
{
QChar op = str[pos];
if (op != '+' && op != '-')
return result;
++pos;
QVariant term = evalTerm(str, pos);
if (result.type() == QVariant::Double
&& term.type() == QVariant::Double)
{
if (op == '+')
{
result = result.toDouble() + term.toDouble();
}
else
{
result = result.toDouble() - term.toDouble();
}
}
else
{
result = Invalid;
}
}
return result;
}
QVariant Cell::evalTerm(const QString &str, int &pos) const
{
QVariant result = evalFactor(str, pos);
while (str[pos] != QChar::Null)
{
QChar op = str[pos];
if (op != '*' && op != '/')
return result;
++pos;
QVariant factor = evalFactor(str, pos);
if (result.type() == QVariant::Double
&& factor.type() == QVariant::Double)
{
if (op == '*')
{
result = result.toDouble() * factor.toDouble();
}
else
{
if (factor.toDouble() == 0.0)
{
result = Invalid;
}
else
{
result = result.toDouble() / factor.toDouble();
}
}
}
else
{
result = Invalid;
}
}
return result;
}
QVariant Cell::evalFactor(const QString &str, int &pos) const
{
QVariant result;
bool negative = false;
if (str[pos] == '-')
{
negative = true;
++pos;
}
if (str[pos] == '(')
{
++pos;
result = evalExpression(str, pos);
if (str[pos] != ')')
result = Invalid;
++pos;
}
else
{
QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
QString token;
while (str[pos].isLetterOrNumber() || str[pos] == '.')
{
token += str[pos];
++pos;
}
if (regExp.exactMatch(token))
{
int column = token[0].toUpper().unicode() - 'A';
int row = token.mid(1).toInt() - 1;
Cell *c = static_cast<Cell *>(
tableWidget()->item(row, column));
if (c)
{
result = c->value();
}
else
{
result = 0.0;
}
}
else
{
bool ok;
result = token.toDouble(&ok);
if (!ok)
result = Invalid;
}
}
if (negative)
{
if (result.type() == QVariant::Double)
{
result = -result.toDouble();
}
else
{
result = Invalid;
}
}
return result;
}
#包括“cell.h”
#包括
Cell::Cell()
{
setDirty();
}
QTableWidgetItem*单元格::克隆()常量
{
返回新单元格(*此);
}
void单元格::setData(int角色、常量变量和值)
{
QTableWidgetItem::setData(角色、值);
如果(角色==Qt::EditRole)
{
setDirty();
}
}
QString单元格::公式()常量
{
返回数据(Qt::EditRole).toString();
}
常量QVariant无效;
QVariant单元格::数据(int角色)常量
{
如果(角色==Qt::DisplayRole)
{
如果(此->值().isValid())
返回值().toString();
其他的
返回“####”;
}
else if(角色==Qt::TextAlignmentRole)
{
if(this->value().type()==QVariant::String)
返回int(Qt::AlignCenter | Qt::AlignVCenter);
其他的
返回int(Qt::AlignRight | Qt::AlignVCenter);
}
其他的
{
返回QTableWidgetItem::数据(角色);
}
}
空单元格::setFormula(常量QString和公式)
{
setData(Qt::EditRole,公式);
}
空单元格::setDirty()
{
此->cacheIsDirty=true;
}
QVariant单元格::value()常量
{
if(cacheIsDirty)
{
cacheIsDirty=false;
QString formulaStr=公式();
if(公式str.startsWith('\'')
{
cachedValue=formulaStr.mid(1);
}
else if(formulaStr.startsWith('='))
{
cachedValue=无效;
QString expr=formulaStr.mid(1);
expr.替换(“,”);
expr.append(QChar::Null);
int pos=0;
cachedValue=蒸发压力(expr,pos);
if(expr[pos]!=QChar::Null)
cachedValue=无效;
}
其他的
{
布尔ok;
double d=公式str.toDouble(&ok);
如果(确定)
{
cachedValue=d;
}
其他的
{
cachedValue=公式str;
}
}
}
返回cachedValue;
}
QVariant Cell::evalExpression(常量QString&str,int&pos)常量
{
QVariant结果=evalTerm(str,pos);
while(str[pos]!=QChar::Null)
{
QChar op=str[pos];
if(op!='+'&&op!='-')
返回结果;
++pos;
QVariant term=evalTerm(str,pos);
if(result.type()==QVariant::Double
&&term.type()==QVariant::Double)
{
如果(op=='+')
{
result=result.toDouble()+term.toDouble();
}
其他的
{
result=result.toDouble()-term.toDouble();
}
}
其他的
{
结果=无效;
}
}
返回结果;
}
QVariant单元格::evalTerm(常量QString&str,int&pos)常量
{
QVariant结果=评估因子(str、pos);
while(str[pos]!=QChar::Null)
{
QChar op=str[pos];
如果(op!='*'&&op!='/'))
返回结果;
++pos;
QVariant factor=评估因子(str,pos);
if(result.type()==QVariant::Double
&&factor.type()==QVariant::Double)
{
如果(op=='*')
{
result=result.toDouble()*factor.toDouble();
}
其他的
{
if(factor.toDouble()==0.0)
{
结果=无效;
}
其他的
{
result=result.toDouble()/factor.toDouble();
}
}
}
其他的
{
结果=无效;
}
}
返回结果;
}
QVariant单元格::evalFactor(常量QString&str,int&pos)常量
{
变异结果;
布尔阴性=假;
如果(str[pos]='-')
{
负=真;
++pos;
}
如果(str[pos]=='(')
{
++pos;
结果=外泄压(str,pos);
如果(str[pos]!='))
结果=无效;
++pos;
}
其他的
{
QRegExp regExp(“[A-Za-z][1-9][0-9]{0,2}”);
QString令牌;
while(str[pos].isLetterOrNumber()| | str[pos]=='。)
{
令牌+=str[pos];
++pos;
}
if(regExp.exactMatch(令牌))
{
int column=token[0].toUpper().unicode()-“A”;
int row=token.mid(1).toInt()-1;
单元*c=静态\u转换(
tableWidget()->项(行、列));
如果(c)
{
结果=c->value();
}
其他的
{
结果=0.0;
}
}
其他的
{
布尔ok;
结果=token.toDouble(&ok);
如果(!ok)
结果=无效;
}
}
如果(否定)
{
if(result.type()==QVariant::Double)
{
result=-result.toDouble();
}
其他的
{
重新