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. [Solved]error: expected ‘)’ before ‘*’ token when trying to make parent class variables accesible for child class.
Forum Updated to NodeBB v4.3 + New Features

[Solved]error: expected ‘)’ before ‘*’ token when trying to make parent class variables accesible for child class.

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 5.3k Views 1 Watching
  • 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.
  • S Offline
    S Offline
    SetBetterPass
    wrote on 16 Mar 2013, 14:01 last edited by
    #1

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 16 Mar 2013, 19:27 last edited by
      #2

      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

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SetBetterPass
        wrote on 16 Mar 2013, 20:17 last edited by
        #3

        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.

        1 Reply Last reply
        0

        1/3

        16 Mar 2013, 14:01

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved