Help rolling own lambda connect for Qt 4.8
-
@SPlatten said in Help rolling own lambda connect for Qt 4.8:
clsLambda objLambda(& {
qDebug() << "HERE";
});C++ basics - how long does this object live?
-
I want to create a lambda connect for Qt 4.8, using a later version of Qt just isn't an option at the moment, so I would like to add my own.
Is this something that is possible to do with Qt 4.8 and the toolset it has available?
-
@SPlatten I don't ever used Qt 4.x, but perhaps this article could help you: http://silmor.de/qtstuff.lambda.php
@KroMignon , funny enough I found that link just after posting there, looking at that now, thank you.
-
@KroMignon , funny enough I found that link just after posting there, looking at that now, thank you.
-
@KroMignon Trying it now...will let you know when I've tested it.
-
@KroMignon , it could the very old tools that this company is using:
gcc (Gentoo 4.6.3 p1.13,pie-0.5.2) and Qt 4.8.4
When I try to compile including the <functional> header which is present I get:
../clsLambda.h:29:5: error: 'function' in namespace 'std' does not name a type ../clsLambda.h:32:28: error: expected ')' before '<' token ../clsLambda.h: In member function 'void clsLambda::slot()': ../clsLamdba.h:37:24: error: 'mpFN' was not declared in this scope make: *** [moc_clsLambda.o] Error 1 12:27:31 The process "/usr/bin/make" exited with code 2The header:
#include <functional> #include <QObject> class clsLambda : public QObject { Q_OBJECT private: std::function<void()>mpFN; //This is line 29 public: clsLambda(std::function<void()> pFN, QObject* pParent = 0) //This is line 32 : mpFN(pFN) { } public slots: void slot() { if ( mpFN ) mpFN(); } //This is line 37 }; -
@KroMignon , it could the very old tools that this company is using:
gcc (Gentoo 4.6.3 p1.13,pie-0.5.2) and Qt 4.8.4
When I try to compile including the <functional> header which is present I get:
../clsLambda.h:29:5: error: 'function' in namespace 'std' does not name a type ../clsLambda.h:32:28: error: expected ')' before '<' token ../clsLambda.h: In member function 'void clsLambda::slot()': ../clsLamdba.h:37:24: error: 'mpFN' was not declared in this scope make: *** [moc_clsLambda.o] Error 1 12:27:31 The process "/usr/bin/make" exited with code 2The header:
#include <functional> #include <QObject> class clsLambda : public QObject { Q_OBJECT private: std::function<void()>mpFN; //This is line 29 public: clsLambda(std::function<void()> pFN, QObject* pParent = 0) //This is line 32 : mpFN(pFN) { } public slots: void slot() { if ( mpFN ) mpFN(); } //This is line 37 };I manged to remove the compiler warnings and compile by changing the class to:
#include <QObject> class clsLambda : public QObject { Q_OBJECT private: void(*mpFN)(); public: clsLambda(void(*pFN)()) : mpFN(pFN) { } public slots: void slot() { if ( mpFN ) mpFN(); } }; -
@KroMignon , it could the very old tools that this company is using:
gcc (Gentoo 4.6.3 p1.13,pie-0.5.2) and Qt 4.8.4
When I try to compile including the <functional> header which is present I get:
../clsLambda.h:29:5: error: 'function' in namespace 'std' does not name a type ../clsLambda.h:32:28: error: expected ')' before '<' token ../clsLambda.h: In member function 'void clsLambda::slot()': ../clsLamdba.h:37:24: error: 'mpFN' was not declared in this scope make: *** [moc_clsLambda.o] Error 1 12:27:31 The process "/usr/bin/make" exited with code 2The header:
#include <functional> #include <QObject> class clsLambda : public QObject { Q_OBJECT private: std::function<void()>mpFN; //This is line 29 public: clsLambda(std::function<void()> pFN, QObject* pParent = 0) //This is line 32 : mpFN(pFN) { } public slots: void slot() { if ( mpFN ) mpFN(); } //This is line 37 };@SPlatten said in Help rolling own lambda connect for Qt 4.8:
When I try to compile including the <functional> header which is present I get:
Did you enable C++11 support?
I guess you have to add-std=c++11in CXXFLAGS.
With qmake, you can add in pro fileQMAKE_CXXFLAGS += -std=c++11
Or it may also be-std=c++0x, depending on GCC version. -
I want to create a lambda connect for Qt 4.8, using a later version of Qt just isn't an option at the moment, so I would like to add my own.
Is this something that is possible to do with Qt 4.8 and the toolset it has available?
@SPlatten you could use verdigris
https://github.com/woboq/verdigristhat should work, but no guarantee :D
-
@SPlatten said in Help rolling own lambda connect for Qt 4.8:
When I try to compile including the <functional> header which is present I get:
Did you enable C++11 support?
I guess you have to add-std=c++11in CXXFLAGS.
With qmake, you can add in pro fileQMAKE_CXXFLAGS += -std=c++11
Or it may also be-std=c++0x, depending on GCC version.@KroMignon , I've modified the pro file:
QT += core gui CONFIG += c++11 CONFIG += sdk_no_version_check QMAKE_CXXFLAGS += -std=c++11 ...When I try to build I get:
ccplus: error: unrecognized command line option '-std=c++11' -
@SPlatten you could use verdigris
https://github.com/woboq/verdigristhat should work, but no guarantee :D
-
@KroMignon , I've modified the pro file:
QT += core gui CONFIG += c++11 CONFIG += sdk_no_version_check QMAKE_CXXFLAGS += -std=c++11 ...When I try to build I get:
ccplus: error: unrecognized command line option '-std=c++11'@SPlatten said in Help rolling own lambda connect for Qt 4.8:
When I try to build I get:
ccplus: error: unrecognized command line option '-std=c++11'You are using GCC 4.6 (which is very old!), so you should use
-std=c++0xto enabled C++11 support (cf. https://gcc.gnu.org/gcc-4.6/cxx0x_status.html) -
@J-Hilk I clicked on link and was met with:
Error Message: Access to the requested URL has been denied (blocked-category-message)@SPlatten well, here's the general website:
https://woboq.com/blog/verdigris-qt-without-moc.html -
@SPlatten said in Help rolling own lambda connect for Qt 4.8:
When I try to build I get:
ccplus: error: unrecognized command line option '-std=c++11'You are using GCC 4.6 (which is very old!), so you should use
-std=c++0xto enabled C++11 support (cf. https://gcc.gnu.org/gcc-4.6/cxx0x_status.html)@KroMignon , its not working, with the changes to the pro file so builds without problems and the clsLambda now like:
class clsLambda : public QObject { Q_OBJECT private: std::function<void()>mpFN; public: clsLambda(std::function<void()> pFN) : mpFN(pFN) { } public slots: void lambdaSlot() { if ( mpFN ) mpFN(); } };The test code:
clsLambda objLambda([&]() { qDebug() << "HERE"; }); bool blnRC(QObject::connect(pobjAct, SIGNAL(triggered()), &objLambda, SLOT(lambdaSlot()))); qDebug() < blnRC;blnRC is always true, but when a menu is selected there is no sign of HERE in the Application Output.
-
@SPlatten said in Help rolling own lambda connect for Qt 4.8:
clsLambda objLambda(& {
qDebug() << "HERE";
});C++ basics - how long does this object live?
-
@SPlatten said in Help rolling own lambda connect for Qt 4.8:
clsLambda objLambda(& {
qDebug() << "HERE";
});C++ basics - how long does this object live?
@Christian-Ehrlicher , the lambda is an inline function, what do you mean?
-
@SPlatten said in Help rolling own lambda connect for Qt 4.8:
clsLambda objLambda(& {
qDebug() << "HERE";
});C++ basics - how long does this object live?
@Christian-Ehrlicher , sorry, I know exactly what you meant and I will change the code to allow for a life of the object outside of the initial set-up, the example on the original link:
https://silmor.de/qtstuff.lambda.phpIs IMHO wrong and I agree with you.
-
@Christian-Ehrlicher , the lambda is an inline function, what do you mean?