Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. error: C2027: use of undefined type 'Ui::MainWindow'
QtWS25 Last Chance

error: C2027: use of undefined type 'Ui::MainWindow'

Scheduled Pinned Locked Moved Solved General and Desktop
11 Posts 5 Posters 6.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.
  • R Offline
    R Offline
    RanDev123
    wrote on last edited by RanDev123
    #1

    I've created a Qt widget application project, the mainwindow just being the default generated mainwindow and after a while the mainwindow.cpp wouldn't compile, even after commenting out everything that I had added to the .h or .cpp, giving the following errors on the initializer and destuctor :
    mainwindow.cpp:7: error: allocation of incomplete type 'Ui::MainWindow'
    mainwindow.cpp:15: warning: deleting pointer to incomplete type 'Ui::MainWindow' may cause undefined behavior
    mainwindow.cpp:7: error: C2027: use of undefined type 'Ui::MainWindow'
    mainwindow.cpp:9: error: C2027: use of undefined type 'Ui::MainWindow'
    mainwindow.cpp:9: error: C2227: left of '->setupUi' must point to class/struct/union/generic type
    mainwindow.cpp:15: warning: C4150: deletion of pointer to incomplete type 'Ui::MainWindow'; no destructor called
    Code (Minus previously mentioned commented out bits):
    mainwindow.h:
    #ifndef MAINWINDOW_H
    #define MAINWINDOW_H

    #include <QMainWindow>

    namespace Ui {
    class MainWindow;
    }

    class MainWindow : public QMainWindow
    {
    Q_OBJECT

    public:
    explicit MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    private:
    Ui::MainWindow *ui;

    };

    #endif // MAINWINDOW_H

    mainwindow.cpp:

    #include "mainwindow.h"
    #include "ui_mainwindow.h"

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {
    ui->setupUi(this);
    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    This is the same as the default generated class, and another project which complies perfectly and doesn't give any errors, so I'm really confused as to what is happening, any help would be appreciated.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums.
      Try to delete the build folder and then Rebuild all.
      There can be left overs from other compiles.

      R 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi and welcome to the forums.
        Try to delete the build folder and then Rebuild all.
        There can be left overs from other compiles.

        R Offline
        R Offline
        RanDev123
        wrote on last edited by
        #3

        @mrjj The error still persists after doing that

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Can you show your .pro file ?

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

          R 1 Reply Last reply
          2
          • dheerendraD Offline
            dheerendraD Offline
            dheerendra
            Qt Champions 2022
            wrote on last edited by
            #5

            @RanDev123 said in error: C2027: use of undefined type 'Ui::MainWindow':

            mainwindow

            Looks like you have deleted mainwindow.ui file from the project. Is the file called mainwindow.ui listed under Forms ? Just check you have commented this line in your pro file under FORMS.

            Dheerendra
            @Community Service
            Certified Qt Specialist
            http://www.pthinks.com

            R 1 Reply Last reply
            2
            • SGaistS SGaist

              Hi,

              Can you show your .pro file ?

              R Offline
              R Offline
              RanDev123
              wrote on last edited by
              #6

              @SGaist

              #-------------------------------------------------

              Project created by QtCreator 2018-12-09T17:41:52

              #-------------------------------------------------

              QT += core gui

              greaterThan(QT_MAJOR_VERSION, 4): QT += widgets

              TARGET = CPU_Simulation
              TEMPLATE = app

              The following define makes your compiler emit warnings if you use

              any feature of Qt which has been marked as deprecated (the exact warnings

              depend on your compiler). Please consult the documentation of the

              deprecated API in order to know how to port your code away from it.

              DEFINES += QT_DEPRECATED_WARNINGS

              You can also make your code fail to compile if you use deprecated APIs.

              In order to do so, uncomment the following line.

              You can also select to disable deprecated APIs only up to a certain version of Qt.

              #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0

              CONFIG += c++11

              SOURCES +=
              main.cpp
              controlunit.cpp
              register.cpp
              memorybus.cpp
              databus.cpp
              addressbus.cpp
              controlbus.cpp
              arithlogunit.cpp
              indatabus.cpp
              mainwindow.cpp
              alucontrolbus.cpp
              memory.cpp
              binaryutilities.cpp

              HEADERS +=
              controlunit.h
              register.h
              memorybus.h
              databus.h
              addressbus.h
              controlbus.h
              arithlogunit.h
              indatabus.h
              mainwindow.h
              alucontrolbus.h
              memory.h
              binaryutilities.h

              FORMS +=
              mainwindow.ui

              Default rules for deployment.

              qnx: target.path = /tmp/$${TARGET}/bin
              else: unix:!android: target.path = /opt/$${TARGET}/bin
              !isEmpty(target.path): INSTALLS += target

              1 Reply Last reply
              0
              • dheerendraD dheerendra

                @RanDev123 said in error: C2027: use of undefined type 'Ui::MainWindow':

                mainwindow

                Looks like you have deleted mainwindow.ui file from the project. Is the file called mainwindow.ui listed under Forms ? Just check you have commented this line in your pro file under FORMS.

                R Offline
                R Offline
                RanDev123
                wrote on last edited by RanDev123
                #7

                @dheerendra
                Its still there under forms
                I can edit its design and stuff, its also still in the project folder and in the .pro file

                1 Reply Last reply
                0
                • dheerendraD Offline
                  dheerendraD Offline
                  dheerendra
                  Qt Champions 2022
                  wrote on last edited by dheerendra
                  #8

                  Do you see following header files under build directory ? > #include "ui_mainwindow.h"

                  Can you paste the content of the above file ? It is possible that you have changed the object name of MainWindow object in designer.

                  Dheerendra
                  @Community Service
                  Certified Qt Specialist
                  http://www.pthinks.com

                  R 1 Reply Last reply
                  0
                  • dheerendraD dheerendra

                    Do you see following header files under build directory ? > #include "ui_mainwindow.h"

                    Can you paste the content of the above file ? It is possible that you have changed the object name of MainWindow object in designer.

                    R Offline
                    R Offline
                    RanDev123
                    wrote on last edited by
                    #9

                    @dheerendra The class in the ui_mainwindow.h file was called MainWindoe instead of MainWindow, I think I made a spelling mistake when creating the project, but I thought I corrected it in all relevant files, I don't know why this persisted, even after deleting the build folder, I changed the name and it complies now, thank you

                    1 Reply Last reply
                    1
                    • dheerendraD Offline
                      dheerendraD Offline
                      dheerendra
                      Qt Champions 2022
                      wrote on last edited by
                      #10

                      Looks like you changed in the names files. Actually you should change the object name in the designer. Look at the property window in Designer. It has property called objectName. Looks like you have changed this also.

                      Dheerendra
                      @Community Service
                      Certified Qt Specialist
                      http://www.pthinks.com

                      1 Reply Last reply
                      0
                      • enjoysmathE Offline
                        enjoysmathE Offline
                        enjoysmath
                        wrote on last edited by enjoysmath
                        #11

                        Only way to fix this is to recreate your whole project, dropping in all your source files. At least this gives you an excuse to re-organize your folder structure. This is my second time encountering it and organizing is what I plan to do.

                        Okay, I was able to fix this by renaming (in QtDesigner to MainWindowClass), compiling, error still there. Rename again to MainWindow. Compile, more errors. Then finally rename it back to MainWindowClass. Save in Qt Deigner. Clean build in VS and rebuild. Errors now gone. VS sucks.

                        https://github.com/enjoysmath
                        https://math.stackexchange.com/users/26327/exercisingmathematician

                        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