View Full Version : Expected class-name before '{' token
imagiro1
15th June 2009, 20:39
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:
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include "ui_mainwindow.h"
class MainWindow : public QWidget, private Ui::MainWindowDLG
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
public slots:
void display_pic();
};
#endif
I know it's got to be something simple I am overlooking. Thanks in advance.
spirit
15th June 2009, 20:51
add #include <QWidget> in this file, e.g.
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include "ui_mainwindow.h"
...
imagiro1
15th June 2009, 20:59
Tried it, same result.
spirit
15th June 2009, 21:00
attach all sources.
imagiro1
15th June 2009, 21:09
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.
spirit
15th June 2009, 21:12
no, I was asking you to upload your sources, that I can try to compile your project by myself.
imagiro1
15th June 2009, 21:20
Sorry. Here we go...
main.cpp
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow *dialog = new MainWindow;
dialog->show();
return app.exec();
}
mainwindow.cpp
#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()
{
QPixmap pixmap("Dima.jpg");
label_image->setPixmap(pixmap);
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QWidget>
#include "ui_mainwindow.h"
class MainWindow : public QWidget, private Ui::MainWindowDLG
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
public slots:
void display_pic();
};
#endif
ui_mainwindow.h
/************************************************** ******************************
** 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:
QWidget *centralWidget;
QLabel *label_image;
QPushButton *pushButton_display;
void setupUi(QMainWindow *MainWindow)
{
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 = new QPushButton(centralWidget);
pushButton_display->setObjectName(QString::fromUtf8("pushButton_display"));
pushButton_display->setGeometry(QRect(330, 480, 113, 32));
MainWindow->setCentralWidget(centralWidget);
retranslateUi(MainWindow);
QMetaObject::connectSlotsByName(MainWindow);
} // setupUi
void retranslateUi(QMainWindow *MainWindow)
{
MainWindow->setWindowTitle(QApplication::translate("MainWindow", "MainWindow", 0, QApplication::UnicodeUTF8));
label_image->setText(QString());
pushButton_display->setText(QApplication::translate("MainWindow", "Push Me", 0, QApplication::UnicodeUTF8));
Q_UNUSED(MainWindow);
} // retranslateUi
};
namespace Ui {
class MainWindow: public Ui_MainWindow {};
} // namespace Ui
QT_END_NAMESPACE
#endif // UI_MAINWINDOW_H
spirit
15th June 2009, 21:35
try this
mainwindow.cpp
#include "mainwindow.h"
#include <QtGui>
#include <QPixmap>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(this)
{
setupUi(this);
connect( pushButton_display, SIGNAL( clicked() ), this, SLOT( display_pic() ) );
}
void MainWindow::display_pic()
{
QPixmap pixmap("Dima.jpg");
label_image->setPixmap(pixmap);
}
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "ui_mainwindow.h"
class MainWindow : public QMainWindow, private Ui::MainWindowDLG
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
public slots:
void display_pic();
};
#endif
Lykurg
15th June 2009, 22:00
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(this)
Hi, a short side question. I pass everytime parent to the ctor of the base class. What's the advantage of passing this?
spirit
15th June 2009, 22:03
mistyped, of course must be passed parent.
wysota
15th June 2009, 22:05
Did you add the "mainwindow.ui" file to your project file and reran qmake? I guess you did... nevermind...
Lykurg
15th June 2009, 22:13
mistyped, of course must be passed parent.
Fine, than I can stop thinking about :D
imagiro1
16th June 2009, 06:26
Still not working. :confused:
spirit
16th June 2009, 07:18
ok, attach to your next post an archive with sources, pro-file and ui-file.
wysota
16th June 2009, 09:43
Are we blind or what?
The class is called Ui::MainWindow, not Ui::MainWindowDLG!
The line should say:
class MainWindow : public QMainWindow, private Ui::MainWindow
spirit
16th June 2009, 10:48
Are we blind or what?
The class is called Ui::MainWindow, not Ui::MainWindowDLG!
The line should say:
class MainWindow : public QMainWindow, private Ui::MainWindow
damn, you are right! :D
imagiro1
16th June 2009, 12:37
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.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.