【问题标题】:two qt ui header file namespace issue两个qt ui头文件命名空间问题
【发布时间】:2020-04-24 04:07:11
【问题描述】:

我有两个 ui 标头 - ui_FlowChartEditor.hui_Notepad.h

这段代码有问题:

//ui_FlowChartEditor.h
namespace Ui {
    class FlowChartEditorClass: public Ui_FlowChartEditorClass {};
} // namespace Ui
//ui_Notepad.h
namespace Ui {
    class NotepadClass: public Ui_NotepadClass {};
} // namespace Ui

'Ui' 命名空间重复,所以我通过更改命名空间的名称来解决这个问题。

像这样:

//ui_FlowChartEditor.h
namespace Ui_FlowChartEditor {
    class FlowChartEditorClass: public Ui_FlowChartEditorClass {};
} // namespace Ui
//ui_Notepad.h
namespace Ui_Notepad {
    class NotepadClass: public Ui_NotepadClass {};
} // namespace Ui

它适用于 Debug 配置,但不适用于 Release 配置。

编译器说:[error C2653: 'Ui_FlowChartEditor': is not a class or namespace name (compile source file FlowChartEditor.cpp)], etc..

有没有办法解决这个问题?

提前致谢。

通过@zgyarmati的解决方案,我解决了这个问题。

我在 Qt Designer 中更改了 objectName。

ui_头文件变成了这样:

namespace FlowChartEditorUi {
    namespace Ui {
        class FlowChartEditorClass : public Ui_FlowChartEditorClass {};
    } // namespace Ui
} // namespace FlowChartEditorUi

谢谢。

【问题讨论】:

    标签: c++ qt user-interface


    【解决方案1】:

    ui_*.h 文件由 uic 从您的表单 (.ui) 文件中重新生成。您仅为调试版本更改了生成的ui_*.h 文件,但没有为发布版本更改,因此您在那里拥有原始的 uic 生成文件。 您也可以为发布版本更改文件,但是 您不应该更改生成的文件,因为它们将被覆盖。 要为您的 ui 类设置命名空间,当您在 QtCreator 中创建设计器表单类时,请指定带有命名空间的名称,例如Ui_Notepad::NotepadClass 在“类名”字段中,生成的ui_*.h 文件将包含该命名空间。

    如果您已经有了表单,那么您还可以在 QtCreator 表单编辑器中相应地更改它们的“objectName”属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-05
      • 1970-01-01
      • 2015-08-05
      • 2010-11-04
      相关资源
      最近更新 更多