PDA

View Full Version : closeEvent



jochen_r
14th January 2006, 03:06
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

high_flyer
14th January 2006, 03:17
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 (http://doc.trolltech.com/3.3/designer-manual-5.html) on the subject.

jochen_r
14th January 2006, 11:34
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

high_flyer
14th January 2006, 15:49
try adding
#include "mainform.h"
to the ui.h file.

anda_skoa
14th January 2006, 16:55
Or even better: do not use the ui.h Hack unless you know exactly what you are doing.

Cheers,
_

jochen_r
14th January 2006, 17:02
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

anda_skoa
14th January 2006, 18:17
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,
_

high_flyer
16th January 2006, 13:05
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).