Quantcast
Channel: Jobs
Viewing all articles
Browse latest Browse all 18427

How can I use variables from parent class in child?

$
0
0
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_OBJECT   public:     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.

Viewing all articles
Browse latest Browse all 18427

Trending Articles