Welcome! Log In Create A New Profile

Advanced

Exam prep

Posted by ShaunGVW 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Anonymous User
Re: Exam prep
November 20, 2009 02:11PM
@Rick, please give me the page numbers of the examples of public signals. My understanding of this is that only the owner of the signal should emit a signal and this is consistent with the Observer pattern(the observer is no longer a passive "observer" if it can abirtrarily generate the signal that its meant to just listen for). Also I found this from the QT manuals

Quote

Only the class that defines a signal and its subclasses can emit the signal.

from http://doc.trolltech.com/4.1/signalsandslots.html
Anonymous User
Re: Exam prep
November 20, 2009 02:22PM
Heya Bini. On the first page of the doc for Version 4.5.2 is a piece of code:

Language: C++
#include <QObject>   class Counter : public QObject { Q_OBJECT   public: Counter() { m_value = 0; }   int value() const { return m_value; }   public slots: void setValue(int value);   signals: void valueChanged(int newValue);   private: int m_value; };

[edit]: I see the page hasn't changed over the versions
Anonymous User
Re: Exam prep
November 20, 2009 02:27PM
Notice though that there's no access specifier for the "signals:"

from the textbook

Quote

A signal is implicitly protected, and so are all the identifiers that appear between it and the next access specifier.
Anonymous User
Re: Exam prep
November 20, 2009 02:37PM
yeah but the "public" modifier is above it. It trickles down. From where in the textbook are you getting your info from?

[edit] never mind, found it.
Anonymous User
Re: Exam prep
November 20, 2009 02:42PM
no in this case it doesnt, there's no access specifier for signals because they known to be always protected. Both the textbook and QT manuals explicitly state this. If you don't trust this, try and emit the "public" signal from another class that's not derived from the class in question and see if you succeed.
Anonymous User
Re: Exam prep
November 20, 2009 02:56PM
ok, tried to explicitly specify an access modifier for "signals" and got a compiler error.
avatar
Rey
Re: Exam prep
November 20, 2009 03:04PM
http://www.codeproject.com/KB/books/designpatternsqt4.aspx

Search "A signal is implicitly protected"

Just to clarify. I never even thought about it. You would want it to be inheritable by sub-classes, but not public to be emitted outside of the class. What could go wrong if it got emitted outside the class?

----
"Flying is learning how to throw yourself at the ground and miss." - Douglas Adams
"Time is a great teacher, but unfortunately it kills all its pupils ..." - Louis Hector Berlioz
I think animal testing is a terrible idea; they get all nervous and give the wrong answers.
Anonymous User
Re: Exam prep
November 20, 2009 03:12PM
AFAIK, every gui object emits a signal. This has been harnessed by Qt. It doesn't make sense that another object can "hijack" a signal
Anonymous User
Re: Exam prep
November 20, 2009 03:14PM
It defeats the purpose for what it was created for. Remember, this is an implementation of the Observer pattern, and one of the characteristics of the pattern is that the Subject is always the one that prompts the Observer to action, its never the other way around
Anonymous User
Re: Exam prep
November 20, 2009 03:17PM
nvm
Re: Exam prep
November 21, 2009 10:03AM
@Rev With respect to Patterns Learnt/Learning

What about Strategy?

I am also looking at Monostate, which does not get mentioned much but is on page 242.

Otherwise my list is the same.
avatar Re: Exam prep
November 21, 2009 11:22AM
Serializer is missing

Cobus Neethling
Anonymous User
Re: Exam prep
November 21, 2009 01:35PM
The strategy pattern listed in tut203 doesn't look right to me. It seems that their solution is merely a use of polymorphism. There's no context being used to initialize the strategy.
Re: Exam prep
November 21, 2009 03:35PM
@Corbus - Thanks, I had left that off my list as well.

@Rick
I am not really qualified to comment about your views on the Strategy in tut203 (I just do not know enough), however when I simply compare the UML given in the tut with that given on http://patterns.cs.up.ac.za/UMLdiagrams.shtml (Diagram 7.2), they look very similar.
Anonymous User
Re: Exam prep
November 21, 2009 03:52PM
in this diagram, why is there a dotted arrow (which I understand means "has a dependency on" ) between the client and the command. I would've thought client works only through invoker.


Anonymous User
Re: Exam prep
November 22, 2009 09:49AM
never mind.
avatar Re: Exam prep
November 22, 2009 01:02PM
A signal is protected because the emitting class must be the only one that may be able to call it. If you make it public, it may be called anywhere and for any reason, usually out of context of the signal itself. However, all signals may be registered by any class using the connect() function.


The Qt keywords, slots, signals, emitr are not valid c++ keywords. The framework uses precompiler macros to do the trickery behind the scenes. If you look at the definitions, you get:

#define slots
#define signals protected
#define emit

They are used primarily by MOC to create extra functions that handle MetaObject things.
Sorry, only registered users may post in this forum.

Click here to login