Expected class-name before '{' token
I've working on my first project and I've hit a speed bump. When building, I get this error message. Expected class-name before '{' token in mainwindow.h line 8.
Here is mainwindow.h:
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
class MainWindow
: public QWidget,
private Ui
::MainWindowDLG{
Q_OBJECT
public:
public slots:
void display_pic();
};
#endif
I know it's got to be something simple I am overlooking. Thanks in advance.
Re: Expected class-name before '{' token
add #include <QWidget> in this file, e.g.
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include "ui_mainwindow.h"
...
Re: Expected class-name before '{' token
Re: Expected class-name before '{' token
Re: Expected class-name before '{' token
Attached #include <QWidget> too all other files main.cpp, mainwindow.cpp, and mainwindow.h. I think that is what you wanted me to try. Still get the same error message.
Re: Expected class-name before '{' token
no, I was asking you to upload your sources, that I can try to compile your project by myself.
Re: Expected class-name before '{' token
Sorry. Here we go...
main.cpp
Code:
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
MainWindow *dialog = new MainWindow;
dialog->show();
return app.exec();
}
mainwindow.cpp
Code:
#include "mainwindow.h"
#include <QtGui>
#include <QPixmap>
MainWindow
::MainWindow(QWidget *parent
){
setupUi(this);
connect( pushButton_display, SIGNAL( clicked() ), this, SLOT( display_pic() ) );
}
void MainWindow::display_pic()
{
label_image->setPixmap(pixmap);
}
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include "ui_mainwindow.h"
class MainWindow
: public QWidget,
private Ui
::MainWindowDLG{
Q_OBJECT
public:
public slots:
void display_pic();
};
#endif
ui_mainwindow.h
Code:
/********************************************************************************
** Form generated from reading ui file 'mainwindow.ui'
**
** Created: Mon Jun 15 22:04:49 2009
** by: Qt User Interface Compiler version 4.5.1
**
** WARNING! All changes made in this file will be lost when recompiling ui file!
********************************************************************************/
#ifndef UI_MAINWINDOW_H
#define UI_MAINWINDOW_H
#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QMainWindow>
#include <QtGui/QPushButton>
#include <QtGui/QWidget>
QT_BEGIN_NAMESPACE
class Ui_MainWindow
{
public:
{
if (MainWindow->objectName().isEmpty())
MainWindow
->setObjectName
(QString::fromUtf8("MainWindow"));
MainWindow->resize(770, 524);
MainWindow
->setStyleSheet
(QString::fromUtf8("background-color: rgb(136, 162, 255);\n"""));
centralWidget
= new QWidget(MainWindow
);
centralWidget
->setObjectName
(QString::fromUtf8("centralWidget"));
label_image
= new QLabel(centralWidget
);
label_image
->setObjectName
(QString::fromUtf8("label_image"));
label_image
->setGeometry
(QRect(10,
10,
751,
461));
label_image
->setStyleSheet
(QString::fromUtf8("background-color: rgba(62, 99, 255, 43);"));
pushButton_display
->setObjectName
(QString::fromUtf8("pushButton_display"));
pushButton_display
->setGeometry
(QRect(330,
480,
113,
32));
MainWindow->setCentralWidget(centralWidget);
retranslateUi(MainWindow);
} // setupUi
{
Q_UNUSED(MainWindow);
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
Re: Expected class-name before '{' token
try this
mainwindow.cpp
Code:
#include "mainwindow.h"
#include <QtGui>
#include <QPixmap>
MainWindow
::MainWindow(QWidget *parent
){
setupUi(this);
connect( pushButton_display, SIGNAL( clicked() ), this, SLOT( display_pic() ) );
}
void MainWindow::display_pic()
{
label_image->setPixmap(pixmap);
}
mainwindow.h
Code:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ui_mainwindow.h"
class MainWindow
: public QMainWindow,
private Ui
::MainWindowDLG{
Q_OBJECT
public:
public slots:
void display_pic();
};
#endif
Re: Expected class-name before '{' token
Quote:
Originally Posted by
spirit
Code:
MainWindow
::MainWindow(QWidget *parent
)
Hi, a short side question. I pass everytime parent to the ctor of the base class. What's the advantage of passing this?
Re: Expected class-name before '{' token
mistyped, of course must be passed parent.
Re: Expected class-name before '{' token
Did you add the "mainwindow.ui" file to your project file and reran qmake? I guess you did... nevermind...
Re: Expected class-name before '{' token
Quote:
Originally Posted by
spirit
mistyped, of course must be passed parent.
Fine, than I can stop thinking about :D
Re: Expected class-name before '{' token
Still not working. :confused:
Re: Expected class-name before '{' token
ok, attach to your next post an archive with sources, pro-file and ui-file.
Re: Expected class-name before '{' token
Are we blind or what?
The class is called Ui::MainWindow, not Ui::MainWindowDLG!
The line should say:
Code:
class MainWindow
: public QMainWindow,
private Ui
::MainWindow
Re: Expected class-name before '{' token
Quote:
Originally Posted by
wysota
Are we blind or what?
The class is called Ui::MainWindow, not Ui::MainWindowDLG!
The line should say:
Code:
class MainWindow
: public QMainWindow,
private Ui
::MainWindow
damn, you are right! :D
Re: Expected class-name before '{' token
That's it! Builds without any problems. Of course when I try to run the program I get an error message and the program doesn't start. "The application image_2 quit unexpectedly" And I got to ignore, report, or relaunch. I guess the fun is just beginning. Thanks for your help. I got a feeling I'll be back.