some docu on lambda
authorKonrad Rosenbaum <konrad@silmor.de>
Sun, 15 Jan 2012 10:17:19 +0000 (11:17 +0100)
committerKonrad Rosenbaum <konrad@silmor.de>
Sun, 15 Jan 2012 10:17:19 +0000 (11:17 +0100)
src/misc/lambda.cpp
src/misc/lambda.h

index 2d26b9e..eb29a60 100644 (file)
@@ -1,10 +1,10 @@
 //
 // C++ Implementation: lambda object
 //
-// Description: 
+// Description: allows to use lambda expressions (C++ 11) with Qt4
 //
 //
-// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008-2011
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2012
 //
 // Copyright: See README/COPYING.GPL files that come with this distribution
 //
 
 #include "lambda.h"
 
-#include <QDebug>
-#include <QWidget>
-
 MLambda::MLambda(std::function< void() > l, QObject* parent): QObject(parent)
 {
        m_ptr=l;
 }
 
-MLambda::MLambda(QObject* parent): QObject(parent)
-{
-       m_ptr=0;
-}
-
 void MLambda::call()
 {
        if(m_ptr)
index e396125..912f1fa 100644 (file)
@@ -4,7 +4,7 @@
 // Description: miscellaneous helper functions
 //
 //
-// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2008-2011
+// Author: Konrad Rosenbaum <konrad@silmor.de>, (C) 2012
 //
 // Copyright: See README/COPYING.GPL files that come with this distribution
 //
 #include <functional>
 
 #include <QObject>
-class QWidget;
 
+///wrapper for simple lambda expression, so it can be used with signals
 class MLambda:public QObject
 {
        Q_OBJECT
        public:
+               ///instantiates the lambda object, e.g.
+               /// \code
+               ///int x=55;
+               ///QPushButton button("Push me!");
+               ///MLambda lambda([&x](){qDebug()<<"x is"<<x;});
+               ///connect(&button,SIGNAL(clicked()),&lambda,SLOT(call()));
+               ///button.show();
+               /// \endcode
+               ///the above code will show the value of the variable 'x' whenever the user clicks the button
                MLambda(std::function<void ()>l,QObject* parent = 0);
-               MLambda(QObject* parent = 0);
        public slots:
+               ///generic slot that transparently executes the lambda expression
                void call();
        private:
                std::function<void()>m_ptr;