如何在 Qt Creator 中重命名文件和类?

发布于 10-29 19:47 字数 138 浏览 6 评论 0原文

如何在 Qt Creator 2.0 中重命名文件和类(声明、实现和使用)?

我在那里找不到这样的功能。

How do I rename files and classes (declaration, implementation and uses) in Qt Creator 2.0?

I can't find such feature in there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

葬心2024-11-05 19:47:12

Qt Creator 中没有这样的功能 :(

您可以这样做:

要重命名文件:

  • 关闭项目
  • 在 Windows 资源管理器或其他工具中重命名文件
  • 打开项目
  • 更新 *.pro 文件,在 中列出 *.h 文件headers中的 *.CPP 文件、表单中的 *.ui 文件
  • 更新 #include 部分中的所有 *.ccp 文件以包含

要更改的 正确文件类名 您可以使用 Ctrl + Shift + R 功能来更改头文件和源文件中的类名。

There is no such feature in Qt Creator :(

This is what you can do:

To rename files:

  • close your project
  • rename files in Windows Explorer or some other tool
  • open project
  • update *.pro file, list *.h files in headers, *.CPP files in sources, *.ui files in forms
  • update all *.ccp files in the #include section to include proper files

To change class names you can use the Ctrl + Shift + R feature that changes class names in header files and source files.

沩ん囻菔务2024-11-05 19:47:12

如果您还想重命名表单及其类,则必须编辑 name.ui 文件并更改 小部件名称class 到新的对应值。

您还需要重命名 name.h 文件中的一些内容。

namespace Ui {
    class NewValueHere;
}

private:
    Ui::NewValueHere* mUI;

在您的 name.cpp 文件中,您还必须调整创建 mUI 的调用。

mUI(new Ui::NewValueHere)

If you also want to rename a form and along with its class, you have to edit your name.ui file and change the widget name and class to the new corresponding value.

You also need to rename some things in your name.h file.

namespace Ui {
    class NewValueHere;
}

private:
    Ui::NewValueHere* mUI;

In your name.cpp file you also have to adjust the call of creating your mUI.

mUI(new Ui::NewValueHere)

疯狂的代价2024-11-05 19:47:12

就我个人而言,我需要做更多的事情。

我将我的类“Form”重命名为“MainWindow”,我必须进入目录“build-yourproject...-Debug\ui_mainwindow.h”并将每个“Form”替换为“MainWindow”(Ctrl+f)和然后它起作用了。

编辑:这是一个手动解决方案,它更改在每次构建时重新加载的文件,因此此更改会自动丢失。正确的解决方案是进入 Qt Creator,在右上角的“Object”名称下,您应该有您的类的名称,这就是您需要更改的名称。

Personnally I needed to do something more.

I renamed my class "Form" to "MainWindow", and I had to go in the directory "build-yourproject...-Debug\ui_mainwindow.h" and replace every "Form" with "MainWindow" (Ctrl+f) and then it worked.

EDIT: This was a manual solution that changes a file that is re-loaded at every build, so this change is automatically lost. The right solution is to go in Qt Creator and in the upper-right corner, under the name "Object", you should have the name of your class, that is what you need to change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文