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 5.5k 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.
  • J JonB
    3 Apr 2022, 17:11

    @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 3 Apr 2022, 17:19 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
    
    
    J 1 Reply Last reply 3 Apr 2022, 17:23
    0
    • Q Qt embedded developer
      3 Apr 2022, 17:19

      @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
      
      
      J Offline
      J Offline
      JonB
      wrote on 3 Apr 2022, 17:23 last edited by JonB 4 Mar 2022, 17:29
      #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
      • C Online
        C Online
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on 3 Apr 2022, 17:27 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

        J 1 Reply Last reply 3 Apr 2022, 17:28
        3
        • C Christian Ehrlicher
          3 Apr 2022, 17:27

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

          J Offline
          J Offline
          JonB
          wrote on 3 Apr 2022, 17:28 last edited by
          #10

          @Christian-Ehrlicher Ooohhhh! :)

          Q 1 Reply Last reply 3 Apr 2022, 17:59
          0
          • J JonB
            3 Apr 2022, 17:28

            @Christian-Ehrlicher Ooohhhh! :)

            Q Offline
            Q Offline
            Qt embedded developer
            wrote on 3 Apr 2022, 17:59 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

            J 1 Reply Last reply 3 Apr 2022, 18:05
            0
            • Q Qt embedded developer
              3 Apr 2022, 17:59

              @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

              J Offline
              J Offline
              JonB
              wrote on 3 Apr 2022, 18:05 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 4 Apr 2022, 05:40
              0
              • J JonB
                3 Apr 2022, 18:05

                @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 4 Apr 2022, 05:40 last edited by
                #13

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

                jsulmJ 1 Reply Last reply 4 Apr 2022, 05:44
                0
                • Q Qt embedded developer
                  4 Apr 2022, 05:40

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

                  jsulmJ Online
                  jsulmJ Online
                  jsulm
                  Lifetime Qt Champion
                  wrote on 4 Apr 2022, 05:44 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 12 Apr 2022, 11:25
                  2
                  • jsulmJ jsulm
                    4 Apr 2022, 05:44

                    @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 12 Apr 2022, 11:25 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 12 Apr 2022, 11:28
                    0
                    • Q Qt embedded developer
                      12 Apr 2022, 11:25

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

                      jsulmJ Online
                      jsulmJ Online
                      jsulm
                      Lifetime Qt Champion
                      wrote on 12 Apr 2022, 11:28 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