Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
qtws26_logo

The Qt Event of the Year: Qt World Summit 2026

Save Your Spot >
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. UI file Custom Widget Class Name Generating Issue
Qt 6.12 LTS is out! See what's new in the release blog

UI file Custom Widget Class Name Generating Issue

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
4 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • CaagalarC Offline
    CaagalarC Offline
    Caagalar
    wrote on last edited by
    #1

    Hello,

    I've been testing Qt almost two weeks. I prefer to use Cmake and Visual Studio Code for the development.
    I prefer to use my class name which start with capital letter. You can see the UI file relevant parts

    <customwidget>
       <class>RenderArea</class>
       <extends>QWidget</extends>
       <header>renderarea.h</header>
       <container>1</container>
      </customwidget>
     </customwidgets>
    

    But everytime cmake generate the header file with lower name like that.
    Take a look at the renderarea class name

    /********************************************************************************
    ** Form generated from reading UI file 'mainwindow.ui'
    **
    ** Created by: Qt User Interface Compiler version 5.12.1
    **
    ** WARNING! All changes made in this file will be lost when recompiling UI file!
    ********************************************************************************/
    
    #ifndef UI_MAINWINDOW_H
    #define UI_MAINWINDOW_H
    
    #include <QtCore/QVariant>
    #include <QtWidgets/QApplication>
    #include <QtWidgets/QMainWindow>
    #include <QtWidgets/QMenuBar>
    #include <QtWidgets/QStatusBar>
    #include <QtWidgets/QToolBar>
    #include <QtWidgets/QWidget>
    #include "renderarea.h"
    
    QT_BEGIN_NAMESPACE
    
    class Ui_MainWindow
    {
    public:
        QWidget *centralWidget;
        renderarea *renderWidget;
        QMenuBar *menuBar;
        QToolBar *mainToolBar;
        QStatusBar *statusBar;
    
        void setupUi(QMainWindow *MainWindow)
        {
            if (MainWindow->objectName().isEmpty())
                MainWindow->setObjectName(QString::fromUtf8("MainWindow"));
            MainWindow->resize(834, 595);
            centralWidget = new QWidget(MainWindow);
            centralWidget->setObjectName(QString::fromUtf8("centralWidget"));
            renderWidget = new renderarea(centralWidget);
            renderWidget->setObjectName(QString::fromUtf8("renderWidget"));
            renderWidget->setGeometry(QRect(100, 70, 251, 211));
            MainWindow->setCentralWidget(centralWidget);
            menuBar = new QMenuBar(MainWindow);
            menuBar->setObjectName(QString::fromUtf8("menuBar"));
            menuBar->setGeometry(QRect(0, 0, 834, 21));
            MainWindow->setMenuBar(menuBar);
            mainToolBar = new QToolBar(MainWindow);
            mainToolBar->setObjectName(QString::fromUtf8("mainToolBar"));
            MainWindow->addToolBar(Qt::TopToolBarArea, mainToolBar);
            statusBar = new QStatusBar(MainWindow);
            statusBar->setObjectName(QString::fromUtf8("statusBar"));
            MainWindow->setStatusBar(statusBar);
    
            retranslateUi(MainWindow);
    
            QMetaObject::connectSlotsByName(MainWindow);
        } // setupUi
    
        void retranslateUi(QMainWindow *MainWindow)
        {
            MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", nullptr));
        } // retranslateUi
    
    };
    
    namespace Ui {
        class MainWindow: public Ui_MainWindow {};
    } // namespace Ui
    
    QT_END_NAMESPACE
    
    #endif // UI_MAINWINDOW_H
    
    

    Is there any proper solution for this ? My cmake configuration automoc is on btw.

    set(CMAKE_AUTOMOC ON)
    set(CMAKE_AUTOUIC ON)
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      The ui file is not generated by cmake but by uic.
      Please show us your complete ui file.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      2
      • CaagalarC Offline
        CaagalarC Offline
        Caagalar
        wrote on last edited by
        #3

        When I changed widget class="renderarea" to widget class="RenderArea" , the problem is fixed. But I still don't get it. I'm sure that the header file name and class name entered correclly from Design Tools. Why this is happening ?

        <property name="windowTitle">
           <string>MainWindow</string>	   <string>MainWindow</string>
          </property>	  </property>
          <widget class="QWidget" name="centralWidget"/>	  
        <widget class="QWidget" name="centralWidget">
           <widget class="renderarea" name="renderWidget" native="true">
            <property name="geometry">
             <rect>
              <x>100</x>
              <y>70</y>
              <width>251</width>
              <height>211</height>
             </rect>
            </property>
           </widget>
          </widget>
          <widget class="QMenuBar" name="menuBar">	  <widget class="QMenuBar" name="menuBar">
           <property name="geometry">	   <property name="geometry">
            <rect>	    <rect>
        @@ -35,6 +46,14 @@
          <widget class="QStatusBar" name="statusBar"/>	  <widget class="QStatusBar" name="statusBar"/>
         </widget>	 </widget>
         <layoutdefault spacing="6" margin="11"/>	 <layoutdefault spacing="6" margin="11"/>
         <customwidgets>
          <customwidget>
           <class>RenderArea</class>
           <extends>QWidget</extends>
           <header>renderarea.h</header>
           <container>1</container>
          </customwidget>
         </customwidgets>
         <resources/>	
         <resources/>
         <connections/>	
         <connections/>
        </ui>	
        </ui>
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Maybe you first named it 'renderarea'? I would un-promote the widget and re-promote it to be sure the correct class name is used.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt
          • Unsolved