刚开始学习qt 好多方法搞不懂咋用 百度了半天也无解

img

报错:widget.cpp:31:33: error: invalid operands to binary expression ('QCharRef' and 'char')https://img-mid.csdnimg.cn/release/static/image/mid/ask/399396776946117.png "#left")

qmargins.h:177:34: note: candidate function not viable: no known conversion from 'QCharRef' to 'const QMargins' for 1st argument
qmargins.h:409:35: note: candidate function not viable: no known conversion from 'QCharRef' to 'const QMarginsF' for 1st argument
qtransform.h:416:19: note: candidate function not viable: no known conversion from 'QCharRef' to 'const QTransform' for 1st argument
stl_bvector.h:208:3: note: candidate function not viable: no known conversion from 'QCharRef' to 'const std::_Bit_iterator_base' for 1st argument
qmargins.h:159:34: note: candidate function not viable: no known conversion from 'QCharRef' to 'const QMargins' for 1st argument
qmargins.h:391:35: note: candidate function not viable: no known conversion from 'QCharRef' to 'const QMarginsF' for 1st argument
qsize.h:184:37: note: candidate function not viable: no known conversion from 'QCharRef' to 'const QSize' for 1st argument

qpoint.h:198:38: note: candidate function not viable: requires single argument 'p', but 2 arguments were provided
qpoint.h:395:39: note: candidate function not viable: requires single argument 'p', but 2 arguments were provided
qvector2d.h:247:41: note: candidate function not viable: requires single argument 'vector', but 2 arguments were provided

刚开始学习一手QT 但是这个错查了半天百度也没解决

QChar c = s[i];
int n = c - '0';
number.push_back(n);

char c = s.at(i);
int n = c - '0';
number.push_back(n);
试试

你的s是什么 是结构体吗 你怎么能用结构体减char类型呢

你想要实现什么效果

QCharRef不能直接和char类型相减,我没用过QT,不过应该可以实现,你查查文档

你的s数组是字符数组?char型?想要将一个数字压入栈?


// push_back里面修改
s.toStdString()[i] - '0'