Pregunta

well i am new to Qt but not very new to c++ the error comes in effect for recursive inclusions but look at my code i don’t see any recursive inclusions..i think this is something else will anyone help me with following error :

expected class-name before '{' token {

Here is my code :

#ifndef COLE_H
#define COLE_H

#include <QDialog>
#include "mainwindow.h"

namespace Ui {
class COLE;
}

class COLE : public QDialog , public Ui::MainWindow
{
    Q_OBJECT

public:
    explicit COLE(QWidget *parent = 0);
    ~COLE();

private slots:
    void on_pushButton_clicked();

public:
    double var1;

private:
    Ui::COLE *ui;

};


#endif // COLE_H

I know that the problem come from "public Ui::MainWindow" but i'm sure that this how it should be. I check the name of my class and it's MainWindow.

Please some help.

¿Fue útil?

Solución

You seem to have two issues ongoing.

1) You should be including ui_mainwindow.h rather than mainwindow.h as usually that is what is generated by default by the UI compiler (i.e. uic) unless you change it explicitly. I will assume that is not the case here since that is usually not necessary.

As for the second issue, you can make it work in two different ways:

2a) Single inheritance approach: In short, this way, you use composition rather than inheritance from the UI class. So, if you choose to do it this way, you will only need the pointer member as opposed to inheriting the ui class.

2b) Multiple inheritance approach: In short, this way, you use multiple inheritance as its name says rather than composition. You do not use a pointer member this way, but privately inherit from the ui class.

Currently, you seem to have a wrong mixed approached of the two aforementioned cases. Try to stick to one of them.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top