Solved Analysing an icon editor application
-
show function is the last function that you're calling...
Don't know your implementation, but there is the possibility to have cascade calls from function. Use only F11 to see all the called functions.
Kind Regards,
Enrique
-
I've provided all three files contents in the first post here. Please copy and paste them onto a project on your Qt Creator to see whether it's possible to know how other functions are called.
-
@tomy
Hi
It always possible.
But a function like setWindowsTitle are from Qt and it wont step into that code as
the actual code is not included in the installation. only the binary result.Maybe that is what confusing you ?
Also as @Charlie_Hdz says, you are only calling
iconEditor.setWindowTitle(QObject::tr("Icon Editor"));
iconEditor.setIconImage(QImage(":/images/mouse.png"));so none of the other function are called, except those use by the 2 functions.
-
@mrjj
Hi,
Please take a look at the functions below. When I press ctrl+R, the programs starts and execute all functions including these ones too. Do you know how and where in the code the following functions are called?QColor penColor() const { return curColor; } QImage iconImage() const { return image; } int zoomFactor() const { return zoom; } void setPenColor(const QColor &newColor); void setZoomFactor(int newZoom); ~IconEditor(); protected: void mousePressEvent(QMouseEvent *event); void mouseMoveEvent(QMouseEvent *event); void paintEvent(QPaintEvent *event); private: void setImagePixel(const QPoint &pos, bool opaque); QRect pixelRect(int i, int j) const;
-
@tomy said in Analysing an icon editor application:
ctrl+R,
That is normal run. Not debug so no stepping or breakpoint active.
QColor penColor() const { return curColor; } // called when setting property
QImage iconImage() const { return image; } // called when asking for image
int zoomFactor() const { return zoom; } // called when u click stuff
void setPenColor(const QColor &newColor); / called when setting property
void setZoomFactor(int newZoom); // called when u click stuffprotected: // called on mouse use
void mousePressEvent(QMouseEvent *event); // called by qt
void mouseMoveEvent(QMouseEvent *event); // called by qt
void paintEvent(QPaintEvent *event);// called by qt -
That is normal run. Not debug so no stepping or breakpoint active.
I know that. Just said that to make the issue clear, as a bigger shape.
I got the point for the functions except:QColor penColor() const { return curColor; } // called when setting property
void setPenColor(const QColor &newColor); / called when setting property
QImage iconImage() const { return image; } // called when asking for imageDo you mean the three Q_PROPERTY used in the header file by "called when setting property"? If so, then how are they called when I don't use those
Q_PROPERTY
es? Because they seem useless, that is either I use or remove them the program runs and works well.And about "called when asking for image", in what line is there an instruction that asks for the image?
-
@tomy
well its part of a larger system and are very usefull with rest of Qt
http://doc.qt.io/qt-5/properties.htmliconImage() is an access function and it seem its not used.
Its normal to make access function for data user might want to read.
One could also make the image variable public but that is bad design. -
@mrjj
Thanks.very useful with rest of Qt
I saw the page and found it a little advanced for me. In the case of this example, it's simply redundant but it's surely useful for the next stages of Qt when I study, if I've understood your talk above, correctly.
That function is also useless here as of a few before-mentioned functions. I think the author has founded a right structure for uses like that but here has used only the needed functions.
One question in this end, how do you know a method is called by Qt itself? By your experience or is there any clue?
-
@tomy
Yes, its not always you use all access function at once but its part of the design
to better to cope with changes later on.Well when i dont know a function , i press F1 on it (help) and if there is help
its Qt function.
Also, you can ask Creator to show all functions in a file and its then easy to see if part of
an object or must come from other place. -
and if there is help
its Qt function.And no need for our calling; it's called by the system (Qt). Yeah?
Also, you can ask Creator to show all functions in a file and its then easy to see if part of
an object or must come from other place.Did you mean again, using 'Find Usages' which is another appearance of ctrl+F to me?
-
@tomy said in Analysing an icon editor application:
how do you know a method is called by Qt itself?
Well, it depends on the method. If you for example override an event handler in your own class derived from QWidget then it will be called by Qt. There is no simple answer to this question. Read Qt documentation and try to understand how Qt works. In general Qt can only call something it knows about (what belongs to Qt, like event handler) or what you connect to signals.
-
@tomy said
- And no need for our calling; it's called by the system (Qt). Yeah?
Yes most likely.
'Find Usages' which is another appearance of ctrl+F to me?
Find Usage is is better than plain search but yeah, it just searching.
- And no need for our calling; it's called by the system (Qt). Yeah?
-
Thank you both very much.