Qt中forward declaration of struct Ui::xxx的解决

每当你新键一个 QT设计界面, QT会自动生成yyy.ui文件,如

<?xml version="1.0" encoding="UTF-8"?>

<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
 </widget>
 <resources/>
 <connections/>
</ui>

注意到 name = "Form" ;默认都是这个名字,本人就是照搬mainwindow中的代码才导致这个错误,肤浅啊。

当你在你的头文件中引用此界面时,

创建一个命名空间如

namespace Ui {
class xxx;
}

这里的XXX应与.ui文件中的name一致,否则就会导致如标题如述错误.

原文地址:https://www.cnblogs.com/wzxNote/p/5702785.html