[Solved]Problem with incomplete type and forward declaration trying to add new file to project.
-
I am trying to add new file to my project, small find dialog but I have a problem I can't solve. Everything seems OK to me as I compare my header file for find dialog and for main window but anyway I am getting 4 errors
2 times invalid use of incomplete type and 2 times forward declaration. Code is here:
find.h
@
#ifndef FIND_H
#define FIND_H#include <QWidget>
#include "ui_find.h"namespace Ui {
class FindDialog; //here is forward declaration, reported twice
}class FindDialog : public QWidget{
Q_OBJECTpublic:
explicit FindDialog(QWidget *parent =0);
~FindDialog();private :
Ui::FindDialog* ui;public slots:
};
#endif // FIND_H@
find.cpp
@
#include "find.h"FindDialog::FindDialog(QWidget* parent) :
QWidget(parent),
ui(new Ui::FindDialog) //here is invalid use of incomplete type Ui::FindDialog
{
ui->setupUi(this); //and so here}
FindDialog::~FindDialog(){
delete ui;
}
@
the same way I have it made in mainwindow but class name is MainWindow and it's public class of QMainWindow, not QWidget and it's working without any problems.
Can someone help me please?
Thanks. :) -
At a first look it seems ok, did you run qmake after you added the class?
LE: Also look into the file ui_find.h and see the name of the ui class that is in the Ui:: namespace //isn't it simple Find instead of FindDialog, you should have something like:
@
namespace Ui {
class FindDialog: public Ui_FindDialog {};
}
@ -
You have a forward declaration of "Ui::FindDialog" in your header file, yes.
But where is the actual declaration?
Of course you cannot create an instance of a class for which you have only a forward declaration!
In your .cpp file, you normally include the header file created by the "UIC":http://qt-project.org/doc/qt-4.8/uic.html...
--
[EDIT]
Okay, I just noticed that you include "ui_find.h" in your header file. I guess that is the UIC-generated header file.
If you do it like that, then you do not need a forward declaration at all!
But it's better to have a forward declaration, so you can move the include for the UIC header file to the .cpp file.
Also double check what class the UIC header file actually defines. I apparently is not Ui::FindDialog...
-
Thanks Zlatomir I looked into ui_find.h file and found the class name is Ui_Form, added it there and it works now.