Results 1 to 8 of 8

Thread: closeEvent

  1. #1
    Join Date
    Jan 2006
    Posts
    15
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default closeEvent

    Hi,

    from a tutorial I have stolen the following code:

    void mainform::closeEvent( QCloseEvent * )
    {
    fileExit();
    }

    void mainform::fileExit()
    {
    QApplication::exit( 0 );
    }

    The first function doesn't compile, the error I get is:

    n file included from mainform.cpp:30:
    mainform.ui.h:102: error: no `void mainform::closeEvent(QCloseEvent*)' member function declared in class `mainform'
    mainform.cpp: In constructor `mainform::mainform(QWidget*, const char*, unsigned int)':
    mainform.cpp:167: error: 'class mainform' has no member named 'languageChange'
    mainform.cpp: At global scope:
    mainform.cpp:195: error: no `void mainform::languageChange()' member function declared in class `mainform'
    mainform.cpp:195: error: `void mainform::languageChange()' and `virtual void mainform::languageChange()' cannot be overloaded

    The mainform.cpp is completly generated by Qt Designer. Any idea what is missing?

    Thanks,
    Jochen

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: closeEvent

    Let me see if I understand correctly - are you changing the code generated by QDesigner??
    You are aware every time you rebuild your project any changes you did to the auto generated code are lost!
    The right way to do it is to sub class mainform and in that subclass make any custom code you want.
    I recommend you read the docs on the subject.

  3. #3
    Join Date
    Jan 2006
    Posts
    15
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: closeEvent

    Hi,

    no I am not changing the generated code. The code snippet I've shown is from the mainform.ui.h and according to the tutorial I am working through it is perfectly fine change the code inside that file. It's the "color tool" tutorial from doc.trolltech.com.

    Regards,
    Jochen

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: closeEvent

    try adding
    #include "mainform.h"
    to the ui.h file.

  5. #5
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: closeEvent

    Or even better: do not use the ui.h Hack unless you know exactly what you are doing.

    Cheers,
    _

  6. #6
    Join Date
    Jan 2006
    Posts
    15
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: closeEvent

    First question: What do you mean with hack? I am only doing what they do in a tutorial... What would be better?

    Second question: the include doesn't help, now I get:

    jochen@tux:~/Development/moneycalc> make
    /usr/lib/qt3/bin/uic mainform.ui -i mainform.h -o mainform.cpp
    g++ -c -pipe -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -g -Wall -W -O2 -march=i586 -mcpu=i686 -fmessage-length=0 -Wall -g -DQT_NO_DEBUG -DQT_SHARED -DQT_TABLET_SUPPORT -DQT_THREAD_SUPPORT -I/usr/lib/qt3/mkspecs/default -I. -I. -I/usr/include -I/usr/lib/qt3/include -o mainform.o mainform.cpp
    In file included from mainform.cpp:30:
    mainform.ui.h:126: error: no `void mainform::closeEvent(QCloseEvent*)' member function declared in class `mainform'
    mainform.cpp: In constructor `mainform::mainform(QWidget*, const char*, unsigned int)':
    mainform.cpp:167: error: 'class mainform' has no member named 'languageChange'
    mainform.cpp: At global scope:
    mainform.cpp:195: error: no `void mainform::languageChange()' member function declared in class `mainform'
    mainform.cpp:195: error: `void mainform::languageChange()' and `virtual void mainform::languageChange()' cannot be overloaded
    make: *** [mainform.o] Error 1
    jochen@tux:~/Development/moneycalc>


    Regards,
    Jochen

  7. #7
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: closeEvent

    Quote Originally Posted by jochen_r
    First question: What do you mean with hack?
    For example the file is called .h but it is actually a source file.
    You'll have to start Designer or edit the .ui file if you want to add new properties or methods.

    No idea why someone at Trolltech thought it might be good idea back than, but take it as a hint that it is no longer available in Qt4 that they no longer think it is.

    I am only doing what they do in a tutorial... What would be better?
    Deriving (subclassing) the generated class and implement anything additional in the subclass.



    Cheers,
    _

  8. #8
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: closeEvent

    as anda_skoa said, mainform.ui.h is in fact a source file, and as the docs state, its called 'h' file since its always included by the class implamentation.
    The mainform.ui.h needs to be able to access the class definition, which in your case (for reason I can't see) is not happening, even though you added the #include mainform.h.
    One reason for it could be that the order in which things are being done, meaning, that mainform.ui.h is being proccessed before the source was generated from the ui file,but this should not be happen.
    I can't say much more, since I almost never used this method, I usually create a class with designer, and then subclass it in my code (I think most do it like that).

Similar Threads

  1. QSettings and closeEvent()
    By vito49 in forum Newbie
    Replies: 2
    Last Post: 13th October 2008, 17:18
  2. closeEvent help needed
    By sgmurphy19 in forum Qt Programming
    Replies: 1
    Last Post: 5th November 2007, 18:51
  3. closeEvent preventing shutdown
    By gfunk in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2007, 20:41

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.