Results 1 to 4 of 4

Thread: error with constructor or OnInit

  1. #1
    Join Date
    May 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default error with constructor or OnInit

    i have an error with Oninit methode after the make,this error ii dont know why it comes i paste you my error and my code and thx for your help :

    make
    g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/local/include -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -Isrc -Iinc -I. -I. -o App.o src/App.cpp
    src/App.cpp:41: erreur: expected constructor, destructor, or type conversion before «bool»
    make: *** [App.o] Erreur 1


    App.h


    #include <QApplication>

    #ifndef APP
    #define APP

    /*!
    * \class App
    */
    class App
    {
    private:

    Frm *theFrm;
    //public: void App ( void );


    /*!
    * \fn virtual bool OnInit( void );
    * \brief Inits the Application
    */
    virtual bool OnInit( void );
    };

    #endif


    App.cpp


    #include "../src/Frm.cpp"

    #include "../inc/App.h"

    IMPLEMENT_APP( App )



    bool App::OnInit( void )
    {
    theFrm = new Frm( );

    return true;
    }




    Thx

  2. #2
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: error with constructor or OnInit

    You have not declared a default constructor.

  3. #3
    Join Date
    May 2009
    Posts
    15
    Qt products
    Qt4
    Platforms
    Unix/X11

    Unhappy Re: error with constructor or OnInit

    exuse i declared it before and it dont work that's new declaration:

    App.cpp

    #include "../src/Frm.cpp"

    #include "../inc/App.h"

    IMPLEMENT_APP( App )

    App::App( void )
    {}

    bool App::OnInit( void )
    {
    theFrm = new Frm( );

    return true;
    }


    App.h


    class App
    {
    private:

    Frm *theFrm;
    public: App ( void );


    /*!
    * \fn virtual bool OnInit( void );
    * \brief Inits the Application
    */
    virtual bool OnInit( void );

    };

    #endif




    and that's teh error egain :

    make
    g++ -c -pipe -O2 -Wall -W -D_REENTRANT -DQT_NO_DEBUG -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED -I/usr/share/qt4/mkspecs/linux-g++ -I. -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtCore -I/usr/include/qt4/QtGui -I/usr/local/include -I/usr/include/qt4/QtGui -I/usr/include/qt4 -I. -Isrc -Iinc -I. -I. -o App.o src/App.cpp
    src/App.cpp:41: erreur: expected constructor, destructor, or type conversion before «App»
    make: *** [App.o] Erreur 1

  4. #4
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: error with constructor or OnInit

    First of all: use the [ CODE ] tags!

    In your App.h there is no line decalring, or defining Frm type, so the error is because you use Frm and compiler doesn't know what is that. So include the header file with Frm declaration to your App.h, or make the forward declaration:
    Qt Code:
    1. #include <QApplication>
    2.  
    3. #ifndef APP
    4. #define APP
    5.  
    6. class Frm;
    7. /*!
    8. * \class App
    9. */
    10. class App
    11. {
    12. // . . .
    To copy to clipboard, switch view to plain text mode 

    P.S. Remember about CODE tags, without them it's really hard to read your code and in my opinion without CODE tags with so many doxygen comments it's much harder to see anything in your code.
    I would like to be a "Guru"

    Useful hints (try them before asking):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.