gpt4 book ai didi

c++ - QString复制

转载 作者:行者123 更新时间:2023-11-30 00:56:45 24 4
gpt4 key购买 nike

这个问题可能很基础,但今天我遇到了一个错误说

“错误:将‘const QChar’作为‘QChar& QChar::operator=(const QChar&)’的‘this’参数传递会丢弃限定符”

“我不知道这个分配如何取消 Qt ide 预定义的字符串到字符串复制的资格”。

当我使用以下代码将所需数据从一个字符串复制到另一个字符串时

for(int i=reqposition;;i++)
{
if(data.at(i)==',')
break;

temp.at(j)=data.at(i); // ERROR IS HERE
j++;
}

这段代码有什么问题。是否有任何其他有效的方法将数据从一个字符串从指定索引复制到另一个字符串。我该如何解决这个问题。

感谢您的宝贵时间!

最佳答案

const QChar QString::at(int position);

问题是你没有给字符串赋值;您正在分配给 QString::at(int) 调用的 const QChar 结果。

您需要一个可修改的引用:来自 QString documentation:

QCharRef QString::operator[] ( int position ) Returns the character at the specified position in the string as a modifiable reference. Example: QString str;

if (str[0] == QChar('?')) str[0] = QChar('_'); The return value is of type QCharRef, a helper class for QString. When you get an object of type QCharRef, you can use it as if it were a QChar &. If you assign to it, the assignment will apply to the character in the QString from which you got the reference.

关于c++ - QString复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9537711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com