cannot call member function ‘int LabelParse::searchString(label_inf&, std::__cxx11::string&, size_t&, char&)’ without object
时间: 2024-02-27 10:53:41 浏览: 20
这是一个编译错误,它的意思是你在没有创建对象的情况下调用了 LabelParse 类的成员函数 searchString。你需要在调用成员函数之前创建一个类的对象,然后通过该对象来调用成员函数。
示例代码:
```
LabelParse lp;
label_inf li;
std::string str = "example";
size_t pos;
char delim = ':';
int result = lp.searchString(li, str, pos, delim);
```
在上面的代码中,我们首先创建了一个 LabelParse 类的对象 lp,然后调用了它的成员函数 searchString,并传递了必要的参数。请注意,我们使用对象 lp 来调用成员函数 searchString。
相关问题
Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'indexOf')
这个错误通常表示你正在尝试在一个 undefined 或 null 值上使用 indexOf 方法。indexOf 方法用于查找字符串中某个子字符串的位置。当你尝试在一个未定义的变量或空值上调用 indexOf 方法时,会抛出这个错误。
要解决这个问题,你可以在使用 indexOf 方法之前确保你的变量已经被正确地赋值。你可以使用条件语句或者合理的默认值来避免出现 undefined 或 null 值。
例如,你可以检查变量是否存在,并且不为 null 或 undefined,然后再调用 indexOf 方法:
```javascript
if (myVariable && typeof myVariable.indexOf === 'function') {
// 在这里使用 indexOf 方法
}
```
或者,你可以使用默认值来避免 undefined 或 null 值:
```javascript
const index = (myVariable || '').indexOf('searchString');
```
通过上述方法,你可以避免在 undefined 或 null 值上调用 indexOf 方法而导致的 TypeError。希望对你有所帮助!如果还有其他问题,请随时提问。
好像是添加 cursor.movePosition(QTextCursor::StartOfWord); cursor.movePosition(QTextCursor::End);的问题
是的,您说得对。在我的先前的回答中,我不应该添加`cursor.movePosition(QTextCursor::End)`,因为它会将光标移动到文档的末尾,这会导致下一个`find()`方法从文档的末尾开始查找。这是一个错误,并且会导致无法匹配文本。
您可以修改代码,将`cursor.movePosition(QTextCursor::End)`删除,如下所示:
```python
QString searchString = "your string to search for";
QTextDocument* doc = ui->textEdit->document();
QRegularExpression regExp(searchString);
QTextCursor cursor(doc);
while (!cursor.isNull() && !cursor.atEnd()) {
// 在匹配位置上设置格式
QTextCharFormat format;
format.setForeground(Qt::green);
cursor = doc->find(regExp, cursor, QTextDocument::FindWholeWords);
if (!cursor.isNull()) {
// 将光标移动到匹配文本的开头
cursor.movePosition(QTextCursor::StartOfWord);
// 设置格式
cursor.mergeCharFormat(format);
}
}
```
这将允许`find()`方法从文档的开始处重新开始搜索,以便正确匹配所有文本。再次感谢您的指正。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)