Adam Mańkowski
Adam Mańkowski

Reputation: 948

C++ class in namespace does not name type

I have two files player.h and accountTab.h I need references to player() class from player.h in accountTab.h and Ui::accountTab from accountTab.h

In mainwindow.h i declared player() as:

class player *user;

and it works

In player.h i try to declare Ui::accountTab same like player:

class Ui::accountTab *tab;

But it doesn't work. It throws error.

'accountTab' in namespace 'Ui' does not name a type class Ui::accountTab *tab;

accountTab.h:

#include <QMainWindow>
#include <player.h>

namespace Ui {
class accountTab;
}


class accountTab : public QMainWindow
{
    Q_OBJECT

public:
    explicit accountTab(QWidget *parent = 0);
    class player *user;
    ~accountTab();

private slots:
    void on_cleanZoo_clicked();

    void on_collectStars_clicked();

private:
    Ui::accountTab *ui;
};

Upvotes: 1

Views: 6380

Answers (2)

jxs
jxs

Reputation: 11

you can open the .ui file to ensure that the class in .xml file is accountTab(in general,the name of the class generated by .xml is "Form",if you desinge by Qt designer)

Upvotes: 0

alphashooter
alphashooter

Reputation: 314

  1. If you declare a variable, you don't need to use class keyword. The correct declaration is:

    player *user;
    UI::accountTab *tab;
    
  2. Move definition of accountTab class into its namespace, where it's declared:

    namespace Ui {
    
        class accountTab : public QMainWindow
        {
    
        public:
            explicit accountTab(QWidget *parent = 0);
            class player *user;
            ~accountTab();
    
        private:
            void on_cleanZoo_clicked();
    
            void on_collectStars_clicked();
    
        private:
            Ui::accountTab *ui;
        };
    }
    
  3. Using of private slots: and the single word QObject doesn't seem to be correct. Maybe it's just a misprint, but you should fix it.

Upvotes: 2

Related Questions