Results 1 to 14 of 14

Thread: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

  1. #1
    Join Date
    Jul 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    I am making a project for a school project, and im getting this error

    Qt Code:
    1. error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type
    To copy to clipboard, switch view to plain text mode 
    from my code

    Qt Code:
    1. #ifndef __MAIN_H__
    2. #define __MAIN_H__
    3. #include <QMainWindow>
    4. #include <QApplication>
    5. #include <QPushButton>
    6. #include <cstdlib>
    7. #include "ui_menuScreen.h"
    8.  
    9.  
    10. // connects the code to the UI
    11. class mathsGame : public :: QDialog, private Ui::mainScreenDLG
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. // makes a new instance of the main dialog
    17. mainScreenDLG(QDialog *parent = 0);
    18.  
    19.  
    20.  
    21. }
    22.  
    23.  
    24. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    You must name your constructor mathsGame.

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

  3. #3
    Join Date
    Jul 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    ahhh yes, thankyou

    to avoid confusion, i actually wanted the code to read:
    Qt Code:
    1. class mainScreen : public :: QDialog, private Ui::mainScreenDLG
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. mainScreen(QDialog *parent = 0);
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

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

  5. #5
    Join Date
    Jul 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    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’

    Qt Code:
    1. #ifndef __MAIN_H__
    2. #define __MAIN_H__
    3. #include <QMainWindow>
    4. #include <QApplication>
    5. #include <QPushButton>
    6. #include <cstdlib>
    7. #include "ui_menuScreen.h"
    8.  
    9. // connects the code to the UI
    10. class mainScreen : public QDialog, private Ui::mainScreenDLG
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. mainScreen(QDialog *parent = 0);
    16.  
    17. };
    18.  
    19. #endif
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    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:

    Qt Code:
    1. void mainScreenDLG(QDialog *parent = 0);
    To copy to clipboard, switch view to plain text mode 

    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.
    Last edited by GreenScape; 27th July 2010 at 08:36.

  7. #7
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    Quote Originally Posted by Baxter View Post
    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?


    Quote Originally Posted by Baxter View Post
    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>

  8. #8
    Join Date
    Jul 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    i have been using this tutorial to help me
    http://sector.ynet.sk/qt4-tutorial/m...plication.html
    the "myqtapp.h" file is what is being referred to by me

  9. #9
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    download QtCreator and be happy!

  10. #10
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    Qt Code:
    1. #ifndef __MAIN_H__
    2. #define __MAIN_H__
    3. #include <QMainWindow>
    4. #include <QApplication>
    5. #include <QPushButton>
    6. #include <cstdlib>
    7. #include "ui_menuScreen.h"
    8.  
    9. // connects the code to the UI
    10. class mainScreen : public QDialog, private Ui::mainScreenDLG
    11. {
    12. Q_OBJECT
    13.  
    14. public:
    15. mainScreen(QDialog *parent = 0);
    16.  
    17. };
    18.  
    19. #endif
    To copy to clipboard, switch view to plain text mode 

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

  11. #11
    Join Date
    Jul 2010
    Posts
    53
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    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

  12. #12
    Join Date
    Jul 2010
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    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

    Qt Code:
    1. #include <QApplication>
    2. #include <QDataStream>
    3. #include <QtGui>
    4. #include <cstdlib>
    5. #include <ctime>
    6. #include "ui_mainScreen.h"
    7. #include "mainScreen.h"
    8.  
    9. bool selectSum, selectSub, selectMulti, selectDivisi;
    10.  
    11. // code to begin the programme
    12. mainScreen::mainScreen(QDialog *parent)
    13.  
    14. {
    15. setupUi(this);
    16.  
    17. // connect the buttons and labels to the code
    18. connect (btnCheck, SIGNAL( clicked() ), this, SLOT( getPath() ) );
    19.  
    20. };
    To copy to clipboard, switch view to plain text mode 

    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)
    Last edited by Baxter; 27th July 2010 at 12:19.

  13. #13
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    Quote Originally Posted by GreenScape View Post
    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.

    Quote Originally Posted by Baxter
    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>".

  14. #14
    Join Date
    Jul 2010
    Posts
    1

    Default Re: error: ISO C++ forbids declaration of ‘mainScreenDLG’ with no type

    Baxter

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

    mainScreen,MainScreen may be retained by QT Create

Similar Threads

  1. Replies: 12
    Last Post: 29th April 2010, 13:22
  2. Error::defined after prior declaration as dllimport:
    By hasnatzaidi in forum Qt Programming
    Replies: 2
    Last Post: 12th June 2009, 01:37
  3. error: forward declaration of 'struct QPushButton'
    By prykHetQuo in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2009, 23:20
  4. forbids declaration of QHash with no type
    By nina1983 in forum Qt Programming
    Replies: 4
    Last Post: 16th July 2008, 13:05
  5. Forward Class declaration ERROR
    By nleverin in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2007, 08:35

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.