Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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



  • 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.


  • Lifetime Qt Champion

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



  • @mrjj The error still persists after doing that


  • Lifetime Qt Champion

    Hi,

    Can you show your .pro file ?


  • Qt Champions 2017

    @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.



  • @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



  • @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


  • Qt Champions 2017

    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 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


  • Qt Champions 2017

    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.


Log in to reply