PDA

View Full Version : error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type



Baxter
27th July 2010, 07:37
I am making a project for a school project, and im getting this error


error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type
from my code


#ifndef __MAIN_H__
#define __MAIN_H__
#include <QMainWindow>
#include <QApplication>
#include <QPushButton>
#include <cstdlib>
#include "ui_menuScreen.h"


// connects the code to the UI
class mathsGame : public :: QDialog, private Ui::mainScreenDLG
{
Q_OBJECT

public:
// makes a new instance of the main dialog
mainScreenDLG(QDialog *parent = 0);



}


#endif

Lykurg
27th July 2010, 07:45
You must name your constructor mathsGame.

EDIT: and the "::" after public is wrong.

Baxter
27th July 2010, 07:58
ahhh yes, thankyou

to avoid confusion, i actually wanted the code to read:

class mainScreen : public :: QDialog, private Ui::mainScreenDLG
{
Q_OBJECT

public:
mainScreen(QDialog *parent = 0);

Lykurg
27th July 2010, 08:09
Fine, but still, delete the "::", they do not belong to that place.

Baxter
27th July 2010, 08:30
i am now getting these errors for the new code

src/mainScreen.h:12: error: expected class-name before ‘{’ token
src/mainScreen.h:12: error: invalid use of incomplete type ‘struct QDialog’


#ifndef __MAIN_H__
#define __MAIN_H__
#include <QMainWindow>
#include <QApplication>
#include <QPushButton>
#include <cstdlib>
#include "ui_menuScreen.h"

// connects the code to the UI
class mainScreen : public QDialog, private Ui::mainScreenDLG
{
Q_OBJECT

public:
mainScreen(QDialog *parent = 0);

};

#endif

GreenScape
27th July 2010, 08:31
read carefully:

declaration of ‘mainScreenDLG’ with no type
only constructors and destructors has no return type, you just need to add void (or other return type) before mainScreenDLG:


void mainScreenDLG(QDialog *parent = 0);


Fine, but still, delete the "::", they do not belong to that place.

they do! they tell to compiler namespace where QDialog declared. in this case the do nothing beacuse QDialog in global scope.

GreenScape
27th July 2010, 08:34
i am now getting these errors for the new code
src/mainScreen.h:12: error: expected class-name before ‘{’ token


Ui::mainScreenDLG - is not correct class name, maybe you missed something?



i am now getting these errors for the new code
src/mainScreen.h:12: error: invalid use of incomplete type ‘struct QDialog’


add #include <QDialog>

Baxter
27th July 2010, 08:36
i have been using this tutorial to help me
http://sector.ynet.sk/qt4-tutorial/my-first-qt-gui-application.html
the "myqtapp.h" file is what is being referred to by me

GreenScape
27th July 2010, 09:04
download QtCreator and be happy!

ChrisW67
27th July 2010, 09:37
#ifndef __MAIN_H__
#define __MAIN_H__
#include <QMainWindow>
#include <QApplication>
#include <QPushButton>
#include <cstdlib>
#include "ui_menuScreen.h"

// connects the code to the UI
class mainScreen : public QDialog, private Ui::mainScreenDLG
{
Q_OBJECT

public:
mainScreen(QDialog *parent = 0);

};

#endif

Line 7 seems to include the wrong file, which is probably why Ui::mainScreenDLG is unknown.

GreenScape
27th July 2010, 10:05
no, Ui::mainScreenDLG must be in ui_menuScreen.h, look for it.

in fact mainScreenDLG must be the name of the widget class u created in designer.
if mainScreenDLG is not the name of that class replace it with class name

Baxter
27th July 2010, 11:59
the object name is "mainScreenDLG" in the file mainScreen.ui (created in Qt Designer)
i think that it hadnt recognised the mainScreen.ui file until i re-opened it in Designer for some reason. that or i had misnamed it and
but im still getting the "13: error: expected class-name before ‘{’ token"

on a related note, the code from my "mainScreen.cpp" file is experiencing errors


#include <QApplication>
#include <QDataStream>
#include <QtGui>
#include <cstdlib>
#include <ctime>
#include "ui_mainScreen.h"
#include "mainScreen.h"

bool selectSum, selectSub, selectMulti, selectDivisi;

// code to begin the programme
mainScreen::mainScreen(QDialog *parent)

{
setupUi(this);

// connect the buttons and labels to the code
connect (btnCheck, SIGNAL( clicked() ), this, SLOT( getPath() ) );

};

18: error: no matching function for call to ‘mainScreen::connect(<unresolved overloaded function type>, const char*, mainScreen* const, const char*)’

thankyou for everyone in their help! :)

EDIT: the new error was because i had tried to link by button to a function that did not exist (getPath)

ChrisW67
27th July 2010, 23:56
no, Ui::mainScreenDLG must be in ui_menuScreen.h, look for it.
Greenscape, you seem to be confusing me with the author of the broken program.


the object name is "mainScreenDLG" in the file mainScreen.ui (created in Qt Designer)
i think that it hadnt recognised the mainScreen.ui file until i re-opened it in Designer for some reason. that or i had misnamed it and
but im still getting the "13: error: expected class-name before ‘{’ token"

Qmake will generate uic commands for the .ui file "mainScreen.ui" to generate a file "ui_mainScreen.h" that contains the definitions for the objects in the design. Your code defining "class mathsGame" (first post) includes a file called "ui_menuScreen.h", which presumably relates to a different Designer form that does not define mainScreenDLG.

on a related note, the code from my "mainScreen.cpp" file is experiencing errors
Probably because it does not know of an object by the name btnCheck which the error reports as "<unresolved overloaded function type>".

hippo
31st July 2010, 15:19
Baxter

u try to change class name:mainScreen to myMainScreen or rename other

mainScreen,MainScreen may be retained by QT Create