Important: Please read the Qt Code of Conduct -

error: cannot initialize object parameter of type 'Ui_MainWindow' with an expression of type 'Ui::MainWindow'

  • What is the solution of this error? Can anybody help me in this? Thank you

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include <iostream>
    #include <math.h>
    using namespace std;
    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
        , m_timerId(0),
          m_realTime (0.0)
        m_timerId = startTimer(0);
        cout << "Average time step: " << ( (double)m_realTime ) / ( (double)m_steps ) << " s" << endl;
        if ( m_timerId ) killTimer( m_timerId );
        if ( ui ) delete ui;
        ui = 0;
        //delete ui;
    void MainWindow::timerEvent(QTimerEvent *event)
        float timeStep = m_time.restart();
        m_realTime = m_realTime + timeStep / 1000.0f;
        float roll      =  0.0f;
        float pitch     =  0.0f;
            roll  =  180.0f * sin( m_realTime /  10.0f );
            pitch =  90.0f * sin( m_realTime /  20.0f );
            ui->spinBoxRoll  ->setValue( roll      );
            ui->spinBoxPitch ->setValue( pitch     );
        else {
            roll  = (float) ui->spinBoxRoll  ->value();
            pitch = (float) ui->spinBoxPitch ->value();
    //    ui->widgetPFD->setRoll(roll);
    //    ui->widgetPFD->setPitch(pitch);
    //    ui->widgetSix->setRoll(roll);
    //    ui->widgetSix->setPitch(pitch);

  • @suslucoder
    Which line is the error reported on?

  • @JonB sorry, i forgot to mention
    in ui-> setupUi->(this);

  • @suslucoder
    Hover your mouse over the setupUi word/method. What does the signature report? It should be void Ui_MainWindow::setupUi(QMainWindow *MainWindow)? Did you make changes to, say, the ui_mainwindow.h file? Delete all the files in the build output directory (i.e. debug/release depending on how you are building, where that ui_mainwindow.h is) and rebuild from scratch?

  • @JonB it works! thank you

  • @suslucoder
    What works? Do you mean the deleting of all intermediate files and rebuilding from scratch?

  • @JonB yes it is.

  • @suslucoder
    If you changed anything in ui_mainwindow.h this could happen. If you get what seems like an inexplicable error when compiling, wiping the output directory can sometimes resolve. However, this does not apply to normal, run-of-the-mill errors!