我创建了一个QLineEdit,设置了验证器,并使用以下代码将其放在表格中:
ui->moneyTableWidget->setCellWidget(rowsNum, 1, newQLineEdit);
然后,我还有另一个类来操作表格数据,并对列中的每个值进行求和。以下是代码:
int Calculator::calculatePricesSum(QTableWidget &moneyTableWidget){
double total = 0;
QWidget *tmpLineEdit;
QString *tmpString;
for(int row=0; row<moneyTableWidget.rowCount(); row++){
tmpLineEdit = (QLineEdit*)moneyTableWidget.cellWidget(row,1);
tmpString = tmpLineEdit.text();
total += tmpString->toDouble();
}
return total;
}
但是在构建时出现以下错误:
为什么会出现这个转换错误?/home/testpec/src/nokia QT/MoneyTracker-build-simulator/../MoneyTracker/calculator.cpp:11: error: cannot convert ‘QLineEdit*’ to ‘QWidget*’ in assignment
另一个子问题:将表作为引用传递可以节省内存,对吗?这可能是问题所在吗?我正在为诺基亚智能手机开发应用程序,我认为通过值传递对象会浪费内存...(如果这是一个愚蠢的问题,那我很抱歉,因为我对C++和所有指针的东西都有点生疏...)