You mean I call virtual even my Son and Daughter methods ? I thought it was just for the Mother class !
You mean I call virtual even my Son and Daughter methods ? I thought it was just for the Mother class !
At this point thoughtq won't make your code work...Originally Posted by djoul
Try it and see...
Current Qt projects : QCodeEdit, RotiDeCode
It still doesn t work ...
Qt Code:
{ Q_OBJECT public: Mother(); virtual ~Mother(); protected: }; class Son : public Mother { Q_OBJECT public: Son(); virtual ~Son(); protected: } // somewhere in the code : Son *pSon = ... pSon->update();To copy to clipboard, switch view to plain text mode
What does such a code outputs?
Current Qt projects : QCodeEdit, RotiDeCode
djoul (4th July 2006)
In my code, I added the Q_OBJECT that I had forgotten, I tried what you wrote and this is weird, the Son's paintEvent method is never called !!!
I even tried adding a public method draw in my Son class,with just update() in its body.
And then trying son->draw() but nothing happens.
And, if I put just virtual to the Son and Mother paintEvent method I get the error :
V4 error LNK2001: symbole externe non rÚsolu "protected: virtual void __thiscall Mother:aintEvent(class QPaintEvent *)" (?paintEvent@Weather@@MAEXPAVQPaintEvent@@@Z)
I must add =0 to the virtual paintEvent in the Mother class,
or delete the virtual in virtual paintEvent in my Son class.
For me, the natural code would be in the Mother class : virtual void paintEvent(...)=0 and the destructor virtual.
And in My son class : void paintEvent(...){.........} with the destructor not virtual.
(But I almost tried all the possible configurations)
Last edited by djoul; 3rd July 2006 at 10:04.
What should happen? How did you try to invoke it? How did you create that object?Originally Posted by djoul
Could you prepare minimal compilable example that reproduces the problem?
djoul (4th July 2006)
In my Son paintEvent I create a file and write some stuff in it and I try to draw some text on my widget to be sure the function is called but the file is never created, so my paintEvent method is never called.Originally Posted by jacek
In anoter class I just do Son *son = new Son(...);
son->draw() and as I specified draw as public it should work.
I'll try to prepare a minimal example
Might doublecheck that your Son isVisible() or has updatesEnabled() ?
Software Engineer
djoul (4th July 2006)
Hehe, some news : updtatesEnabled do nothing but I tried some Son *son = new Son(...).Originally Posted by gfunk
son->setVisible(true); and then son->update();
And now my paintEvent is called, but I ve new problems : My class Son is supposed to write on a widget but now (I've got a timer that calls update() every second) it creates a new widget each seconds and writes on it.
But that s a different problem, I think it comes from passing the original widget to the Son, I ll dig on it.
Thank you all for your help !
Why do you create new widgets if Son is a widget too? Wouldn't it be enough to redraw Son?Originally Posted by djoul
But I don t want to create new ones ! Qt does ...Originally Posted by jacek
The architecture is :
I've got a class Bck1 and Bck2. In both classes I do some drawing with QPaintEvent (the 2 classes are Widgets).
I ve got then the class Mother with his Son.
And I want the Son to do some drawings in bot he Bck1 and Bck2.
My problem is : Son is not a Widget but he must inherit from QWidget to know where he must paint ?
Qt Code:
#include <QWidget> { Q_OBJECT public : ~Bck2(); ... protected : ...} #include <QWidget> { Q_OBJECT public : ~Bck2(); protected : } #include <QWidget> { Q_OBJECT public : virtual ~Mother(); protected : }; #include <QWidget> class Son : public Mother { Q_OBJECT public : Son(.....);//do I need to put Son(QWidget *parent=0) ... ????? ~Son(); protected : }To copy to clipboard, switch view to plain text mode
Does it seems ok ? I never know if I need to specify *parent or *parent=0, and if I need to put Qwidget *parent in the Son constructor ???
Qt does only what you tell it to do.Originally Posted by djoul
Indeed, the problem is in constructor. If you create a widget without a parent, it will be created as a standalone window. So your constructor should be implemented like this:And the Mother class must pass this parent to QWidget's constructor.Qt Code:
: Mother( parent ) { ... }To copy to clipboard, switch view to plain text mode
That "= 0" part only indicates a default value for the parameter.I never know if I need to specify *parent or *parent=0
Bookmarks