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: cannot initialize object parameter of type 'Ui_MainWindow' with an expression of type 'Ui::MainWindow'

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

Scheduled Pinned Locked Moved Solved General and Desktop
qt5main windowwidget
8 Posts 2 Posters 15.2k 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.
  • D Offline
    D Offline
    deleted286
    wrote on 18 Jan 2021, 08:02 last edited by
    #1

    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_steps(0),
          m_realTime (0.0)
    
    {
        ui->setupUi(this);
        m_timerId = startTimer(0);
        m_time.start();
    }
    
    MainWindow::~MainWindow()
    {
    
        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)
    {
        QMainWindow::timerEvent(event);
    
        float timeStep = m_time.restart();
        m_realTime = m_realTime + timeStep / 1000.0f;
    
        float roll      =  0.0f;
        float pitch     =  0.0f;
    
        if(ui->pushButtonAuto->isChecked())
        {
            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);
    
        m_steps++;
    }
    
    J 1 Reply Last reply 18 Jan 2021, 08:05
    0
    • D deleted286
      18 Jan 2021, 08:02

      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_steps(0),
            m_realTime (0.0)
      
      {
          ui->setupUi(this);
          m_timerId = startTimer(0);
          m_time.start();
      }
      
      MainWindow::~MainWindow()
      {
      
          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)
      {
          QMainWindow::timerEvent(event);
      
          float timeStep = m_time.restart();
          m_realTime = m_realTime + timeStep / 1000.0f;
      
          float roll      =  0.0f;
          float pitch     =  0.0f;
      
          if(ui->pushButtonAuto->isChecked())
          {
              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);
      
          m_steps++;
      }
      
      J Offline
      J Offline
      JonB
      wrote on 18 Jan 2021, 08:05 last edited by
      #2

      @suslucoder
      Which line is the error reported on?

      D 1 Reply Last reply 18 Jan 2021, 08:18
      0
      • J JonB
        18 Jan 2021, 08:05

        @suslucoder
        Which line is the error reported on?

        D Offline
        D Offline
        deleted286
        wrote on 18 Jan 2021, 08:18 last edited by
        #3

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

        J 1 Reply Last reply 18 Jan 2021, 08:49
        0
        • D deleted286
          18 Jan 2021, 08:18

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

          J Offline
          J Offline
          JonB
          wrote on 18 Jan 2021, 08:49 last edited by
          #4

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

          D 1 Reply Last reply 18 Jan 2021, 08:56
          3
          • J JonB
            18 Jan 2021, 08:49

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

            D Offline
            D Offline
            deleted286
            wrote on 18 Jan 2021, 08:56 last edited by
            #5

            @JonB it works! thank you

            J 1 Reply Last reply 18 Jan 2021, 09:02
            0
            • D deleted286
              18 Jan 2021, 08:56

              @JonB it works! thank you

              J Offline
              J Offline
              JonB
              wrote on 18 Jan 2021, 09:02 last edited by
              #6

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

              D 1 Reply Last reply 18 Jan 2021, 09:10
              0
              • J JonB
                18 Jan 2021, 09:02

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

                D Offline
                D Offline
                deleted286
                wrote on 18 Jan 2021, 09:10 last edited by
                #7

                @JonB yes it is.

                J 1 Reply Last reply 18 Jan 2021, 09:40
                0
                • D deleted286
                  18 Jan 2021, 09:10

                  @JonB yes it is.

                  J Offline
                  J Offline
                  JonB
                  wrote on 18 Jan 2021, 09:40 last edited by
                  #8

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

                  1 Reply Last reply
                  1

                  8/8

                  18 Jan 2021, 09:40

                  • Login

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