在项目或文件系统中搜索

搜索范围和搜索条件决定了Qt Creator 在何处查找搜索字符串、如何将字符串与文本匹配以及显示哪些结果。

在所有项目中搜索

  1. 选择Ctrl+Shift+F或转到Edit >Find/Replace >Advanced Find >Open Advanced Find
  2. Scope 中,选择All Projects

    搜索结果视图

  3. Search for 中,输入要查找的字符串。
  4. 选择选项使搜索区分大小写、只搜索整个单词、使用正则表达式或忽略二进制文件。
  5. File pattern 中,指定文件模式,将搜索限制为与模式匹配的文件。例如,要只在.cpp.h 文件中搜索字符串,请输入*.cpp,*.h
  6. Exclusion pattern 中,指定文件模式以从搜索中忽略文件。
  7. 选择Search

如果找不到某些文件,请参阅指定项目内容,了解如何将它们声明为项目的一部分。

在文件系统中搜索

除了从所有项目中搜索的选项外,您还可以选择要使用的搜索引擎和搜索目录。

  1. Scope 中,选择Files in File System

    搜索结果视图

  2. Search for 中,输入要查找的字符串。
  3. Search engine 中,选择要使用的搜索引擎:
    • 选择Internal 可使用Qt Creator 搜索引擎。
    • 要使用 Git 只搜索 Git 工作树中的跟踪文件,请选择Git Grep 。要将搜索限制在 HEAD、标签、本地或远程分支或提交哈希值,请输入一个引用。如果要在文件系统中搜索,请将该字段留空。
    • 选择Silver Searcher 可使用试验性 Silver Searcher 插件。
  4. Directory 中,选择要搜索的目录。选择Browse 查找目录,或选择Current 在当前活动文件所在的目录中搜索。
  5. 选择Search

搜索和替换

替换现有文本的出现次数:

  1. 选择Search & Replace

    搜索和替换时的搜索结果

  2. Replace with 中输入新文本。
  3. 选择Replace

要在替换时保留原始文本的大小写,请选择Preserve case替换时保留大小写中列出的规则也适用于此处。

另请参阅 如何:搜索查找符号打开银色搜索器在当前文件中搜索以及搜索结果视图

Copyright © The Qt Company Ltd. and other contributors. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.