mehr kommentare master
authorKonrad Rosenbaum <konrad@silmor.de>
Mon, 25 Feb 2013 21:19:40 +0000 (22:19 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Mon, 25 Feb 2013 21:19:40 +0000 (22:19 +0100)
LIESMICH.txt
base/thingy.cpp
base/thingy.h
dylib1/lib1.cpp
dylib1/lib1.h
dylib2/lib2.cpp
dylib2/lib2.h
main/main.cpp
main/main.h
main/thready.cpp
main/thready.h

index 7bc4362..fd82705 100644 (file)
@@ -178,4 +178,7 @@ QPointer
 --------
 
 ...ist sehr praktisch wenn man ein QObject nicht besitzt oder es sich
-unvermittelt löschen kann. So wie unser Thread.
\ No newline at end of file
+unvermittelt löschen kann. So wie unser Thread.
+
+Wenn ein QObject gelöscht wird werden alle QPointer die darauf zeigen
+auf NULL gesetzt. Man kann das mit isNull() testen.
\ No newline at end of file
index 3b14031..24d1ea7 100644 (file)
@@ -1,5 +1,5 @@
 #include "thingy.h"
 
-
+//just default implementations
 Thingy::Thingy(){}
 Thingy::~Thingy(){}
index 74d712f..028ea5b 100644 (file)
@@ -3,14 +3,27 @@
 
 #include <QString>
 
+///The Thingy class - it shows how to load library functionality in C++.
+///It is a kind of Plugin.
 class Thingy
 {
         public:
+                ///Create a thingy.
                 Thingy();
+                ///Delete it.
                 virtual ~Thingy();
+                
+                ///Example for an interface that provides functionality.
+                ///
+                ///Normally these are either pure virtual or have a default implementation
+                ///that makes sense in the context.
+                ///
+                ///Usually a plugin interface has lots and lots of those.
+                ///With or without parameters...
                 virtual QString getThingy()=0;
 };
 
+///Convenience function pointer type for the factory function.
 typedef Thingy* (*ThingyFunc)();
 
 #endif
index 0a171f7..457a658 100644 (file)
@@ -1,10 +1,13 @@
 #include "lib1.h"
 
-static int mything=1;
-
+///just return something nice for this interface
 QString Thingy1::getThingy()
 {
         return "Thingy1: "+QString::number(mything++);
 }
 
+///the factory function: returns a thingy implementation
+///
+///it creates a derived instance that actually implementats the interface,
+///but it returns a pointer to the abstract interface base class
 extern "C" Thingy*getthing(){return new Thingy1;}
\ No newline at end of file
index 4441ae7..0a9b94e 100644 (file)
@@ -1,7 +1,12 @@
 #include "../base/thingy.h"
 
+///Implementation number 1 of a Thingy.
+///This is one example of a plugin interface implementations.
 class Thingy1:public Thingy
 {
         public:
+                ///implementation of the interface
                 virtual QString getThingy();
+        private:
+                int mything=1;
 };
\ No newline at end of file
index d1f7853..d84612a 100644 (file)
@@ -1,10 +1,10 @@
 #include "lib2.h"
 
-static int mything=1;
 
 QString Thingy2::getThingy()
 {
-        return "Completely different Thingy 2: "+QString::number(mything++);
+        return QString("Completely different Thingy 2: %1").arg(mything+=1.1);
 }
 
+///the other factory method, see lib1 for details
 extern "C" Thingy*getthing(){return new Thingy2;}
\ No newline at end of file
index e73096e..016ebb6 100644 (file)
@@ -1,7 +1,13 @@
 #include "../base/thingy.h"
 
+///second implementation of the thingy plugin interface
 class Thingy2:public Thingy
 {
         public:
+                ///return something completely different
                 virtual QString getThingy();
+        private:
+                ///it is perfectly alright to add data, as long as we have 
+                ///a virtual destructor - even if it is implicitly defined
+                double mything=0.;
 };
\ No newline at end of file
index 3417b22..81796dc 100644 (file)
@@ -95,6 +95,7 @@ void MainWin::startThread()
 
 void MainWin::pokeThread()
 {
+        //if we still have that thread: poke it
         if(mthread.isNull())
                 mthingylabel->setText("Sorry, cannot poke a null thread");
         else
index 8bec118..8b67712 100644 (file)
@@ -31,12 +31,13 @@ class MainWin:public QDialog
                 ///call that thingy from one of those libraries
                 void callThingy();
         private:
-                //label to show what we are doing
+                ///label to show what we are doing
                 QLabel*mthingylabel;
-                //the library that we loaded
+                ///the library that we loaded
                 QLibrary*mthinglib;
-                //the thingy from that library
+                ///the thingy from that library
                 Thingy*mthingy;
+                ///smart pointer to the thread example
                 QPointer<MyThread>mthread;
 };
 
index 58beffb..6435f4e 100644 (file)
@@ -48,11 +48,13 @@ void MyTask::gotime()
 
 void MyThread::disruptThread()
 {
+        //relay this action
         emit disruptThreadSignal();
 }
 
 void MyTask::disruptThread()
 {
+        //go screw with the counter
         ctr+=1000;
         gotime();
 }
index 136dc28..835c31e 100644 (file)
@@ -14,8 +14,10 @@ class MyThread:public QThread
                 ///\param slot the slot to call for updates, must be SLOT(foo(QString)) or SLOT(foo())
                 static MyThread* startMe(QObject*callee,const char*slot);
         public slots:
+                ///public interface of the proxy/facade to disrupt the counting of the task
                 void disruptThread();
         signals:
+                ///cascade signal to relay this interface to the task
                 void disruptThreadSignal();
         protected:
                 ///internal: creates the thread and remembers who to call
@@ -23,7 +25,7 @@ class MyThread:public QThread
                 ///runs the thread
                 void run()override;
         private:
-                //remember who to call between startMe and run
+                ///remember who to call between startMe and run
                 QObject*mcallee;
                 const char*mcallslot;
 };