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. why i am getting this error: use of undeclared identifier 'MainWindow' ?
Forum Updated to NodeBB v4.3 + New Features

why i am getting this error: use of undeclared identifier 'MainWindow' ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 4 Posters 6.7k 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.
  • Q Qt embedded developer

    @Christian-Ehrlicher no this is not the problem because by default while we make new project this by default added by qt. i think this problem is related to kit. and i don't know how to resolve kit related problem. i don't know which kit i need to add for my simple c++ qt project .i have doubt is that in .pro file

    that by default conains

    # Default rules for deployment.
    qnx: target.path = /tmp/$${TARGET}/bin
    else: unix:!android: target.path = /opt/$${TARGET}/bin
    !isEmpty(target.path): INSTALLS += target
    
    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #4

    @Qt-embedded-developer
    .pro file has nothing to do with it. The error says it is on line #5 of the .cpp file. Why don't you look at what the first 5 lines are?

    Q 1 Reply Last reply
    0
    • JonBJ JonB

      @Qt-embedded-developer
      .pro file has nothing to do with it. The error says it is on line #5 of the .cpp file. Why don't you look at what the first 5 lines are?

      Q Offline
      Q Offline
      Qt embedded developer
      wrote on last edited by Qt embedded developer
      #5

      @JonB for your reference the code for .cpp file is

      #include "mainwindow.h"
      #include "ui_mainwindow.h"
      #include <QDebug>
      
      MainWindow::MainWindow(QWidget *parent)
          : QMainWindow(parent)
          , ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
      
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      

      so just tell me what you want to say about my line 5 problem. i want to understand it. i want to know the solution of it also.

      JonBJ 1 Reply Last reply
      0
      • Q Qt embedded developer

        @JonB for your reference the code for .cpp file is

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QDebug>
        
        MainWindow::MainWindow(QWidget *parent)
            : QMainWindow(parent)
            , ui(new Ui::MainWindow)
        {
            ui->setupUi(this);
        
        }
        
        MainWindow::~MainWindow()
        {
            delete ui;
        }
        
        

        so just tell me what you want to say about my line 5 problem. i want to understand it. i want to know the solution of it also.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #6

        @Qt-embedded-developer said in why i am getting this error: use of undeclared identifier 'MainWindow' ?:

        #include "mainwindow.h"
        #include "ui_mainwindow.h"
        #include <QDebug>

        MainWindow::MainWindow(QWidget *parent)

        So none of the #included files defines MainWindow. Only you have those files. If you want to understand why have a look in them. Maybe you need to force build to regenerate ui_mainwindow.h. Maybe you renamed the class in the .ui file. Maybe your mainwindow.h file is wrong.

        Q 1 Reply Last reply
        0
        • JonBJ JonB

          @Qt-embedded-developer said in why i am getting this error: use of undeclared identifier 'MainWindow' ?:

          #include "mainwindow.h"
          #include "ui_mainwindow.h"
          #include <QDebug>

          MainWindow::MainWindow(QWidget *parent)

          So none of the #included files defines MainWindow. Only you have those files. If you want to understand why have a look in them. Maybe you need to force build to regenerate ui_mainwindow.h. Maybe you renamed the class in the .ui file. Maybe your mainwindow.h file is wrong.

          Q Offline
          Q Offline
          Qt embedded developer
          wrote on last edited by
          #7

          @JonB i have not manually created any file. this is by default file added by qt

          for your reference my mainwindow.h file contain this class defination

          #ifndef MAINWINDOW_H
          #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:
              Ui::MainWindow *ui;
          };
          #endif // MAINWINDOW_H
          
          
          JonBJ 1 Reply Last reply
          0
          • Q Qt embedded developer

            @JonB i have not manually created any file. this is by default file added by qt

            for your reference my mainwindow.h file contain this class defination

            #ifndef MAINWINDOW_H
            #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:
                Ui::MainWindow *ui;
            };
            #endif // MAINWINDOW_H
            
            
            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #8

            @Qt-embedded-developer
            That looks as I would expect. So far I cannot see why you would get the error you reported. Assume there were no other errors reported.

            What about the generated ui_mainwindow.h file from the .ui file, which is in the compilation output (usually Build-...) directory? Force a clean build; you could just delete all the files in that output (not your sources!) directory. Though that should not be the issue....

            1 Reply Last reply
            0
            • Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #9

              There is another mainwindow.h somewhere around which the compiler is using - seeing the other posts about the include path mess this is at least a very good option here...

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              JonBJ 1 Reply Last reply
              3
              • Christian EhrlicherC Christian Ehrlicher

                There is another mainwindow.h somewhere around which the compiler is using - seeing the other posts about the include path mess this is at least a very good option here...

                JonBJ Offline
                JonBJ Offline
                JonB
                wrote on last edited by
                #10

                @Christian-Ehrlicher Ooohhhh! :)

                Q 1 Reply Last reply
                0
                • JonBJ JonB

                  @Christian-Ehrlicher Ooohhhh! :)

                  Q Offline
                  Q Offline
                  Qt embedded developer
                  wrote on last edited by
                  #11

                  @JonB i have deleted the all the files from output directory.

                  my compile output is:

                  10:55:52: Running steps for project part1...
                  10:55:52: Starting: "/usr/bin/x86_64-linux-gnu-qmake" /home/mangal/JAYMOGAL/MYFIRST/part1/part1.pro -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug
                  10:55:52: The process "/usr/bin/x86_64-linux-gnu-qmake" exited normally.
                  10:55:52: Starting: "/usr/bin/make" -f /home/mangal/JAYMOGAL/MYFIRST/build-part1-Qt_5_12_8_System-Debug/Makefile qmake_all
                  make: Nothing to be done for 'qmake_all'.
                  10:55:52: The process "/usr/bin/make" exited normally.
                  10:55:52: Starting: "/usr/bin/make" -j2
                  /usr/lib/qt5/bin/uic ../part1/mainwindow.ui -o ui_mainwindow.h
                  x86_64-linux-gnu-g++ -c -m64 -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../part1 -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o main.o ../part1/main.cpp
                  x86_64-linux-gnu-g++ -m64 -pipe -g -std=gnu++11 -Wall -W -dM -E -o moc_predefs.h /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/dummy.cpp
                  x86_64-linux-gnu-g++ -c -m64 -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../part1 -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o mainwindow.o ../part1/mainwindow.cpp
                  /usr/lib/qt5/bin/moc -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB --include /home/mangal/JAYMOGAL/MYFIRST/build-part1-Qt_5_12_8_System-Debug/moc_predefs.h -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I/home/mangal/JAYMOGAL/MYFIRST/part1 -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/include/c++/9 -I/usr/include/x86_64-linux-gnu/c++/9 -I/usr/include/c++/9/backward -I/usr/lib/gcc/x86_64-linux-gnu/9/include -I/usr/local/include -I/usr/include/x86_64-linux-gnu -I/usr/include ../part1/mainwindow.h -o moc_mainwindow.cpp
                  x86_64-linux-gnu-g++ -c -m64 -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../part1 -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o moc_mainwindow.o moc_mainwindow.cpp
                  x86_64-linux-gnu-g++ -m64 -o part1 main.o mainwindow.o moc_mainwindow.o   -L/usr/X11R6/lib64 /usr/lib/x86_64-linux-gnu/libQt5Widgets.so /usr/lib/x86_64-linux-gnu/libQt5Gui.so /usr/lib/x86_64-linux-gnu/libQt5Core.so /usr/lib/x86_64-linux-gnu/libGL.so -lpthread   
                  10:55:59: The process "/usr/bin/make" exited normally.
                  10:55:59: Elapsed time: 00:07.
                  

                  but still i get this warning in issue window:
                  mainwindow.h:10: error: expected class name

                  JonBJ 1 Reply Last reply
                  0
                  • Q Qt embedded developer

                    @JonB i have deleted the all the files from output directory.

                    my compile output is:

                    10:55:52: Running steps for project part1...
                    10:55:52: Starting: "/usr/bin/x86_64-linux-gnu-qmake" /home/mangal/JAYMOGAL/MYFIRST/part1/part1.pro -spec linux-g++-64 CONFIG+=debug CONFIG+=qml_debug
                    10:55:52: The process "/usr/bin/x86_64-linux-gnu-qmake" exited normally.
                    10:55:52: Starting: "/usr/bin/make" -f /home/mangal/JAYMOGAL/MYFIRST/build-part1-Qt_5_12_8_System-Debug/Makefile qmake_all
                    make: Nothing to be done for 'qmake_all'.
                    10:55:52: The process "/usr/bin/make" exited normally.
                    10:55:52: Starting: "/usr/bin/make" -j2
                    /usr/lib/qt5/bin/uic ../part1/mainwindow.ui -o ui_mainwindow.h
                    x86_64-linux-gnu-g++ -c -m64 -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../part1 -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o main.o ../part1/main.cpp
                    x86_64-linux-gnu-g++ -m64 -pipe -g -std=gnu++11 -Wall -W -dM -E -o moc_predefs.h /usr/lib/x86_64-linux-gnu/qt5/mkspecs/features/data/dummy.cpp
                    x86_64-linux-gnu-g++ -c -m64 -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../part1 -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o mainwindow.o ../part1/mainwindow.cpp
                    /usr/lib/qt5/bin/moc -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB --include /home/mangal/JAYMOGAL/MYFIRST/build-part1-Qt_5_12_8_System-Debug/moc_predefs.h -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -I/home/mangal/JAYMOGAL/MYFIRST/part1 -I/usr/include/x86_64-linux-gnu/qt5 -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets -I/usr/include/x86_64-linux-gnu/qt5/QtGui -I/usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I/usr/include/c++/9 -I/usr/include/x86_64-linux-gnu/c++/9 -I/usr/include/c++/9/backward -I/usr/lib/gcc/x86_64-linux-gnu/9/include -I/usr/local/include -I/usr/include/x86_64-linux-gnu -I/usr/include ../part1/mainwindow.h -o moc_mainwindow.cpp
                    x86_64-linux-gnu-g++ -c -m64 -pipe -g -std=gnu++11 -Wall -W -D_REENTRANT -fPIC -DQT_DEPRECATED_WARNINGS -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../part1 -I. -isystem /usr/include/x86_64-linux-gnu/qt5 -isystem /usr/include/x86_64-linux-gnu/qt5/QtWidgets -isystem /usr/include/x86_64-linux-gnu/qt5/QtGui -isystem /usr/include/x86_64-linux-gnu/qt5/QtCore -I. -I. -I/usr/lib/x86_64-linux-gnu/qt5/mkspecs/linux-g++-64 -o moc_mainwindow.o moc_mainwindow.cpp
                    x86_64-linux-gnu-g++ -m64 -o part1 main.o mainwindow.o moc_mainwindow.o   -L/usr/X11R6/lib64 /usr/lib/x86_64-linux-gnu/libQt5Widgets.so /usr/lib/x86_64-linux-gnu/libQt5Gui.so /usr/lib/x86_64-linux-gnu/libQt5Core.so /usr/lib/x86_64-linux-gnu/libGL.so -lpthread   
                    10:55:59: The process "/usr/bin/make" exited normally.
                    10:55:59: Elapsed time: 00:07.
                    

                    but still i get this warning in issue window:
                    mainwindow.h:10: error: expected class name

                    JonBJ Offline
                    JonBJ Offline
                    JonB
                    wrote on last edited by
                    #12

                    @Qt-embedded-developer said in why i am getting this error: use of undeclared identifier 'MainWindow' ?:

                    but still i get this warning in issue window:
                    mainwindow.h:10: error: expected class name

                    I don't know what the "issue" window is, maybe this is code model warning not from compiler?

                    Q 1 Reply Last reply
                    0
                    • JonBJ JonB

                      @Qt-embedded-developer said in why i am getting this error: use of undeclared identifier 'MainWindow' ?:

                      but still i get this warning in issue window:
                      mainwindow.h:10: error: expected class name

                      I don't know what the "issue" window is, maybe this is code model warning not from compiler?

                      Q Offline
                      Q Offline
                      Qt embedded developer
                      wrote on last edited by
                      #13

                      @JonB what to do to stop code model warning in qt creator ?

                      jsulmJ 1 Reply Last reply
                      0
                      • Q Qt embedded developer

                        @JonB what to do to stop code model warning in qt creator ?

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #14

                        @Qt-embedded-developer said in why i am getting this error: use of undeclared identifier 'MainWindow' ?:

                        what to do to stop code model warning in qt creator ?

                        Disable the Clang plug-in (in Help/About Plugins...)

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

                        Q 1 Reply Last reply
                        2
                        • jsulmJ jsulm

                          @Qt-embedded-developer said in why i am getting this error: use of undeclared identifier 'MainWindow' ?:

                          what to do to stop code model warning in qt creator ?

                          Disable the Clang plug-in (in Help/About Plugins...)

                          Q Offline
                          Q Offline
                          Qt embedded developer
                          wrote on last edited by
                          #15

                          @jsulm when i am disable it my building of project process not get stop. it continuously running.

                          jsulmJ 1 Reply Last reply
                          0
                          • Q Qt embedded developer

                            @jsulm when i am disable it my building of project process not get stop. it continuously running.

                            jsulmJ Offline
                            jsulmJ Offline
                            jsulm
                            Lifetime Qt Champion
                            wrote on last edited by
                            #16

                            @Qt-embedded-developer Clang plug-in has actually nothing to do with the build.
                            Try complete rebuild: delete build folder, run qmake and then build.

                            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