PDA

View Full Version : Overwrite Qt slot ...



jiapei100
29th January 2010, 22:11
Hi, all:

Is it possible to overwrite Qt slot?

For instance:

CFather:


class CFather : public QMainWindow
{
Q_OBJECT
.....
protected slots:
void about();
}

void CFather::about()
{
QMessageBox::information(this,
"Father",
"......");
}




CSon:


class CSon : public CFather
{
Q_OBJECT
.....
protected slots:
void about();
}

void CSon::about()
{
QMessageBox::information(this,
"Son",
"......");
}




I just want to realize:

A CFather object will call CFather::about() when the menu item "about" is invoked.
A CSon object will call CSon::about() when the menu item "about" is invoked.
(Note: CFather and CSon are almost the same QMainWindow with only a little bit modification.
But, I just want the about() will invoke two different dialogs, with clear indication that this is a "Son" or a "Father" window)

I tried "virtual" already, but whenever I clicked "OK" on the poped CSon:about() QMessageBox, it will CSon QMessageBox once again. That is to say, I've got to click "OK" twice to close QMessageBox thoroughly.

How to deal with this problem?

Best Regards
JIA

franz
30th January 2010, 10:54
Slots are fundamentally the same as functions. If the slot is declared virtual, you can override it. If it isn't, you can't.