[Solved]error: expected ‘)’ before ‘*’ token when trying to make parent class variables accesible for child class.
-
I am trying to use QstringList from MainWindow class in child class but I always get following error:
/home/ruli/MD-build-desktop/../MD/find.h:17: error: expected ‘)’ before ‘*’ token
find.h file
@
#ifndef FIND_H
#define FIND_H#include <QDialog>
#include "ui_FindDialog.h"namespace Ui {
class FindDialog : public Ui_Dialog {};
class MainWindow;
}class FindDialog : public QDialog{
Q_OBJECTpublic:
explicit FindDialog(MainWindow *parent =0);//this is line causing error
~FindDialog();private :
Ui::FindDialog* ui;
public slots:
void findMatches();};
#endif // FIND_H
@
find.cpp
@
#include "find.h"FindDialog::FindDialog(MainWindow* parent) :
QDialog(parent),
ui(new Ui::FindDialog)
{
QStringList list;
list=parent->FileList;//FileList is variable I am trying to access from MainWindow class
ui->setupUi(this);
connect(ui->buttonBox->button(QDialogButtonBox::Ok),SIGNAL(clicked()),this,SLOT(findMatches()));}
FindDialog::~FindDialog(){
delete ui;
}
void FindDialog::findMatches(){
//there will come code
}
@I was looking here http://qt-project.org/forums/viewthread/15838/P15 but didn't find any difference, maybe only that my parent is QMainWindow (can this cause the problem? I don't think so but I am still newbie...) and my forward declaration is inside namespace Ui, but as I tried it outside I got even more errors...
Before I was declaring parent as QWidget and everytdhing was ok but I couln't use variables from MainWindow class...
So please tell me what I am doing wrong or if there is better way I can use vars from parent class.
Thanks. -
You're missing an include for the MainWindow so compiler doesn't know what it is. QWidget was working because #include <QDialog> includes also <QWidget>.
Why did you put the forward declaration of MainWindow in the Ui namespace? It probably should be in the global scope and then included properly in the .cpp
-
Thanks man it compiled now without errors (I had FindDialog* findDialog; created in header mainwindow.h which was causing problems too). I put the class mainwindow; part outside and got error ISO C++ forbids declaration of findDialog with no type so I removed it to mainwindow.cpp and its working now.