why i am getting this error: use of undeclared identifier 'MainWindow' ?
-
I have created simple c++ based qt project.
I am using QMake version 3.1
Using Qt version 5.12.8 in /usr/lib/x86_64-linux-gnuby default kit is coming like desktop
but i want to make simple widget application uisng qt c++.
so for that how to add kit that will not show below error.
but what i needwhen i am running the project i am getting below error:
/home/mangal/JAYMOGAL/MYFIRST/part1/mainwindow.cpp:5: error: use of undeclared identifier 'MainWindow'
-
Because you did not declare a class named 'MainWindow' maybe?
-
@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
-
@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? -
@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.
-
@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
#include
d files definesMainWindow
. Only you have those files. If you want to understand why have a look in them. Maybe you need to force build to regenerateui_mainwindow.h
. Maybe you renamed the class in the.ui
file. Maybe yourmainwindow.h
file is wrong. -
@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
-
@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 (usuallyBuild-...
) 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.... -
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...
-
@Christian-Ehrlicher Ooohhhh! :)
-
@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 -
@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 nameI don't know what the "issue" window is, maybe this is code model warning not from compiler?
-
@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...)
-
@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.