I see that Qt puts a class inside the Ui
interface like this:
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
...
Is this method the same as enclosing the entire class inside the namespace? It certainly looks cleaner.
No, in your example Ui::MainWindow
is a different class than the MainWindow
class defined in the global namespace.
Behold:
namespace Ui {
class MainWindow;
}
class MainWindow
{
};
int main()
{
Ui::MainWindow mw; // fails due to incomplete type
}
This code won't compile, since Ui::MainWindow
is an incomplete type.
Most likely, the Qt code was just using a forward declaration. You can forward declare the class in a namespace, but you still must actually implement the class in the same namespace, or else it is not the same class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With