Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to move the QMenuBar definition in a separate UI file
Because I want to generate it by external scripts.
Welcome to devnet.
There's little point in employing separate .ui file just for menu bar since it's basically a list of QActions. You can store it as such and load at runtime. If it really needs to be in a .ui format there's "QUiLoader":http://qt-project.org/doc/qt-5.0/qtuitools/quiloader.html
There's no way to sorta #include one ui into another at compile time. But creating a menu is basically a bunch of addMenu () and addAction() calls so maybe your script can generate that.
I didn't gotcha your idea.
can give me a small demo about how to use QUiLoader to load the QMenuBar?
Assumming that you have a .ui file in your resources defining a menu bar with File->Open menus like this:
<?xml version="1.0" encoding="UTF-8"?>
<widget class="QMenuBar" name="MenuBar">
<widget class="QMenu" name="menuFile">
And you want to load it into your mainwindow you would do so like this:
QMenuBar* menuBar = qobject_cast<QMenuBar*>(loader.load(&file, this));
Some error checking would be nice of course, but that's the general idea.
It's works, thanks very much!