What is the meaning of the Ui namespace that Qt automatically generates?
So, it is in its own βbubbleβ and will not conflict with any other similar class, like the one you create explicitly. Of course, they could make it be called differently and so on, but even then namespaces are good practice in C ++ to deal with them in order to avoid collisions.
Are these two namespaces the same?
Yes, of course, namespaces with the same name inside the same parent namespace are always the same in a project.
I guess I meant why there is a Ui namespace created in Ui_MainWindow.h.
Well, wherever it was created, really? There should be some file where this code is generated, and not pollute any existing source file with the generated code on the fly. As it is called, the way it is, it is again personal taste.
And as the MainWindow class in the Ui namespace in MainWindow.h knows that this is a direct declaration of the MainWindow class in the Ui file, and not created by me.
Well, this has nothing to do with Qt, it's just the basics of C ++. It seems to me that you do not understand what namespaces are and how they are used. It will be "tagged" with a namespace, so the compiler will of course find out which one it belongs to. Now imagine this without a namespace. This would be completely ambiguous for the compiler.
source share