QCreator 设计器小部件无法从程序代码访问

发布于 2025-01-04 01:19:28 字数 530 浏览 1 评论 0原文

前言:我在 Mac OS X Lion 上使用通过 Qt SDK 安装的 Qt Creator 2.4.1(基于 Qt 4.7.4,64 位)。

我正在开发一个项目,其中使用 QCreator 中的设计器创建了一个 UI。我有几个小部件可以正常工作。我通过从设计面板中拖动它来创建一个新的 QPushButton 小部件,并在设计器中设置一些属性。但是,我无法使用 ui->[widget] 约定从源代码访问它。我可以按预期访问表单上的所有其他小部件。对该网站的搜索产生了一个类似的问题,但是指定的解决方案对我不起作用。

我已经尝试过:

  • 干净、完全重建
  • 重新运行 qmake
  • 重新启动 QCreator

我已经检查了 ui 元素生成的 XML,并且包含小部件并具有正确的 objectName 和属性,但设计器的源代码部分看不到它。

Preface: I am using Qt Creator 2.4.1 (based on Qt 4.7.4, 64-bit) on Mac OS X Lion installed via the Qt SDK.

I am working on a project where I have a UI created using the designer in QCreator. I have several widgets working without issue. I created a new QPushButton widget by dragging it from the desiger palette and set some properties in the designer. However, I am unable to access it from the source code using the ui->[widget] convention. I can access every other widget on the form as expected. A search of the site yielded one similar issue, however the solution specified does not work for me.

I've tried:

  • Clean, full rebuild
  • Re-running qmake
  • Restarting QCreator

I have checked the ui element's generated XML and the widget is included and with the correct objectName and properties, yet the source code portion of the designer does not see it.

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

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

发布评论

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

评论(1

一枫情书 2025-01-11 01:19:28

我通过删除当前工作目录、从版本控制中检查最新的源代码并创建一个新项目解决了这个问题。经过进一步检查,我发现每次编译时由 qmake 生成的 ui_mainwindow.h 已被移动到源目录而不是构建目录中,这肯定与 QCreator 造成了一些内部冲突,它不会重新生成它而只是复制旧的到构建文件夹。如果我看到它并节省了重新开始的时间,删除该文件可能会起作用。

I solved this issue by deleting the current working directory, checking out the latest source from version control, and creating a new project. After further scrutiny, I found that ui_mainwindow.h, which is generated every compile by qmake, had been moved into the source directory instead of the build directory, which must have caused some internal conflict with QCreator where it would not regenerate it and just copy the old one to the build folder. Deleting the file probably would have worked if I had seen it and saved me the time of starting fresh.

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