Search code examples
c++qtuser-interfaceqt-creatorqt-designer

How to generate program code from ui-forms?


I have a UI, generated with Qt Designer. It's generates me a XML code like these:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>ColorDialog</class>
 <widget class="QDialog" name="ColorDialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
   and etc

I want to remove this UI and edit a view by C++ code like these:

    for (auto button:m_buttonColorsList)
    {
        m_colorsLayout->addWidget(button);
    }

    m_mainGroupBox->setLayout(m_colorsLayout);

    m_mainLayout->addWidget(m_mainGroupBox);

    setLayout(m_mainLayout);

How I can convert the exiting form to code?


Solution

  • If you want to generate code using the .ui information then you must use uic tool:

    uic filename.ui -g cpp -o filename_ui.h