PDA

View Full Version : Qt namespace Ui



ehnuh
15th October 2012, 03:26
Hi I would like to ask if it is possible to change the namespace 'Ui' generated by Qt to 'UI'. We are currently adhering to coding guidelines that makes use of all capital letters for abbreviations. When we tried this method:

namespace UI
{
class frmMyDisplay;

}

....also

UI::frmMyDisplay


..it generates an error since the ui header generated by Qt makes use of the 'Ui' namespace when we build the project. It is possible by changing the namespace in the ui header generated by Qt to 'UI' but the problem will appear again once the project is rebuilt.

ChrisW67
15th October 2012, 04:46
"Ui" is hardcoded into uic.

Here are some options:

Change QMAKE_UIC in the pro file to point at a script that runs uic normally and then post-processes the output to change the namespace.
Make a modified uic that uses a different namespace name. You could even parameterise it and submit the modified version to the Qt project for the greater good.
Use a namespace alias to limit the "Ui" reference to once at the top of a file:


using namespace UI = Ui; // to give us a coding standards compliant name

Don't use Designer and uic; write your UI in code.
Convince management that spending time worrying about the capitalisation of a generated namespace name that is used in a handful of places in the code is detracting from actually making the program function.


I predict the next argument will be over the naming of the retranslateUi() function in template form code.

ehnuh
15th October 2012, 05:58
thanks for reply!

wysota
15th October 2012, 10:27
There is also this one stupid possibility:


namespace UI {
class Ui_xyz;
};

or even this one (which can be autogenerated using some simple script):


namespace UI {
class xyz : public Ui::xyz {};
}