What is the rationale behind UI namespace in Qt?
In the process of creating a user interface code from UI file Qt creates 2 classes with just the same definition.
class UI_CustomeUIClassFromUIFile
{
//code generated from UI file thru UIC
}
namespace ui
{
class CustomeUIClassFromUIFile public : UI_CustomeUIClassFromUIFi开发者_JAVA技巧le{};
}using namespace ui;
What is the reason for having 2 classes with just one inside UI namespace and other without namspace? Is it to support compiler that has no support for namespace, there is also a macro some thing like QTNAMESPACE.
The macro is QT_BEGIN_NAMESPACE which is what is used if you compiled Qt to be inside of a custom namespace.
As for the 2 classes, I think you answered it your self. You can either use Ui_XXX
or Ui::XXX
. I always prefer the Ui::
method, but to each their own.
So I guess I don't have a real answer as to the rationale other than letting the programmer choose.
qt/trolltech (& now nokia) published a great doclet on API design which talks about best practice for APIs. There might be an explanation for this there.
精彩评论