Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. General talk
  3. Qt 6
  4. Allocation of incomplete type "Ui::MainWindow"
QtWS25 Last Chance

Allocation of incomplete type "Ui::MainWindow"

Scheduled Pinned Locked Moved Solved Qt 6
erroruimainwindow.hincomplete typemainwindow
9 Posts 6 Posters 12.0k 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.
  • A Offline
    A Offline
    Aahi
    wrote on 16 Feb 2022, 16:02 last edited by Aahi
    #1

    I am getting error in initializing the ui pointer in my MainWindow which I think is automatically generated code. I am Using qt 6. and Here my Code :

    MainWindow.cpp

    #include "ui_mainwindow.h"
    #include "SortFactory.h"
    #include "SortObject.h"
    #include <QListView>
    
    
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        init();
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::init()
    {
    
        ui->comboType->setView(new QListView(this));
    
        ui->comboType->addItems(SortFactory::getInstance()->getSortList());
    
    
        connect(ui->btnSort, &QPushButton::clicked, this, [this]{
            const int type = ui->comboType->currentIndex();
            if (type != ui->canvas->getSortType()) {
                SortObject *obj = SortFactory::getInstance()->createSortObject(type, ui->canvas);
                ui->canvas->setSortObject(type, obj);
            }
            ui->canvas->sort(ui->spinCount->value(), ui->spinInterval->value());
        });
    
    
        connect(ui->btnStop, &QPushButton::clicked, this, [this]{
            ui->canvas->stop();
        });
    
        connect(ui->canvas, &MainCanvas::runFlagChanged,
                this, [this](bool running){
            ui->comboType->setEnabled(!running);
            ui->spinCount->setEnabled(!running);
            ui->spinInterval->setEnabled(!running);
            ui->btnSort->setEnabled(!running);
        });
    }
    

    I am getting the main error in the initializer list hence anywhere *ui is used also giving error.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 16 Feb 2022, 16:15 last edited by
      #2

      Take a look into your generated file "ui_mainwindow.h" and you will see that you do not named your widget "MainWindow" but something else. I would guess "mainwindow".

      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
      1
      • A Offline
        A Offline
        Aahi
        wrote on 18 Feb 2022, 05:37 last edited by
        #3

        @Christian-Ehrlicher I have mainwindow.h in which I have this MainWindow class here is the code for that.

        #define MAINWINDOW_H
        
        #include <QMainWindow>
        
        QT_BEGIN_NAMESPACE
        namespace Ui { class MainWindow; }
        QT_END_NAMESPACE
        
        class MainWindow : public QMainWindow
        {
            Q_OBJECT
        
        public:
            MainWindow(QWidget *parent = nullptr);
            ~MainWindow();
        
        private:
            void init();
        
        private:
            Ui::MainWindow *ui;
        };
        
        #endif // MAINWINDOW_H
        
        J 1 Reply Last reply 18 Feb 2022, 06:05
        0
        • A Aahi
          18 Feb 2022, 05:37

          @Christian-Ehrlicher I have mainwindow.h in which I have this MainWindow class here is the code for that.

          #define MAINWINDOW_H
          
          #include <QMainWindow>
          
          QT_BEGIN_NAMESPACE
          namespace Ui { class MainWindow; }
          QT_END_NAMESPACE
          
          class MainWindow : public QMainWindow
          {
              Q_OBJECT
          
          public:
              MainWindow(QWidget *parent = nullptr);
              ~MainWindow();
          
          private:
              void init();
          
          private:
              Ui::MainWindow *ui;
          };
          
          #endif // MAINWINDOW_H
          
          J Offline
          J Offline
          jsulm
          Lifetime Qt Champion
          wrote on 18 Feb 2022, 06:05 last edited by
          #4

          @Aahi Please read again what @Christian-Ehrlicher suggested: "Take a look into your generated file "ui_mainwindow.h" and you will see that you do not named your widget "MainWindow" but something else."

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          2
          • A Offline
            A Offline
            Aahi
            wrote on 19 Feb 2022, 08:35 last edited by
            #5

            @jsulm @Christian-Ehrlicher Thank you so much It is now working I did the following steps in case anyone in the future got the same error.

            1. I checked the ui_mainwindow.h file in that the class in namespace Ui was MainUI so I changed the iterator from Ui::mainwindow" to Ui::MainUI.

            2. I still was getting the error but this time it was "cannot change the iterator from Ui::mainwindow to Ui::MainUI and this was due to the reason that in mainwindow.h the class MainWindow has already declared the variable as Ui::mainwindow *ui so I changed it to Ui::MainUI *ui.

            3. But again got the error No type named "MainUI" in namespace "Ui" and solution was very simple just include ui_mainwindow.h in that and everything is now runnning perfectly fine.

            Again thank you so much to @Christian-Ehrlicher and @jsulm

            1 Reply Last reply
            1
            • A Offline
              A Offline
              Aahi
              wrote on 19 Feb 2022, 13:21 last edited by
              #6

              @Christian-Ehrlicher @jsulm now the only question is how to mark it as solved?

              T 1 Reply Last reply 19 Feb 2022, 22:55
              0
              • A Aahi
                19 Feb 2022, 13:21

                @Christian-Ehrlicher @jsulm now the only question is how to mark it as solved?

                T Offline
                T Offline
                TheLumbee
                wrote on 19 Feb 2022, 22:55 last edited by
                #7

                @Aahi On your previous answer, click on the three dots to the right and mark it as the correct answer.

                1 Reply Last reply
                1
                • T Offline
                  T Offline
                  TrahdBoy
                  wrote on 17 Jun 2024, 04:13 last edited by
                  #8

                  @Aahi please give a visual representation of your solution, i cant understand your answer.

                  SGaistS 1 Reply Last reply 17 Jun 2024, 08:10
                  0
                  • T TrahdBoy
                    17 Jun 2024, 04:13

                    @Aahi please give a visual representation of your solution, i cant understand your answer.

                    SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 17 Jun 2024, 08:10 last edited by
                    #9

                    @TrahdBoy hi,

                    It's all explained here.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    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 Extensions
                    • Unsolved