//
// 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)
// 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;