hotime
2023-10-08 15:42 deepin
就是字面意思呀: ‘class QString’ has no member named ‘first’
QString类没有名为first
的成员函数,所以你不能这么使用。
QVector、QList和QMap才有。
你如果是要从QString类型的字符串中获得某一位字符,应该使用at
如:
QString str = "Hello, world!";
// 获取第一个字符
QChar firstChar = str.at(0);
(信息来源参考自百度AI)
Reply Like 0 View the author
deepin20.9、QT5.15,使用first()、last()报错:
/home/hrhh-zengfc/qttest/sampl04_02_01/widget.cpp👎 In member function ‘void Widget::on_pushButton_23_clicked()’:
/home/hrhh-zengfc/qttest/sampl04_02_01/widget.cpp:62: error: ‘class QString’ has no member named ‘first’
QString str3 = str1.first(N + 1);
^~~~~
/home/hrhh-zengfc/qttest/sampl04_02_01/widget.cpp:64: error: ‘class QString’ has no member named ‘last’; did you mean ‘at’?
str3 = str1.last(str1.size() - N - 1);
^~~~
问题出在哪儿?
烦请大神指教。