Solved Pass a method to QtConcurrent::map
-
@nulluse said:
Your help and patience with my silly questions is certainly appreciated!
I certainly wouldn't call them silly, this is pretty specific matter and as I said, in practice it mostly doesn't come up.
-
When I was using Netbeans with GCC under Linux and FreeBSD, the below lambda declared in a descendant of
QDialog
worked fine:auto func = [ // 96 x0 = widget.spX0->value(), // 97 y0 = widget.spY0->value(), ] (int& iteration) -> int { // 102 return iteration; };
widget.spX0
etc are the double spin boxes on the dialog.But now I tried Qt Creator under Win7 and this lambda is throwing a bunch of errors:
newform.cpp:97: error: C2143: syntax error : missing ']' before '=' newform.cpp:97: error: C3481: 'x0': lambda capture variable not found newform.cpp:102: error: C2059: syntax error : ']' newform.cpp:97: error: C2059: syntax error : '='
Do I need to switch the language version to C++11 anywhere?
-
@nulluse said:
Do I need to switch the language version to C++11 anywhere?
Depending on the compiler and Qt version, probably, yes. You can add
CONFIG += c++11
to your project file and if the compiler supports it it'll be enabled. -
That did not help.
This is what I just downloaded and installed with Qt 5.6 as the only version checked off in the setup:Qt Creator 3.6.1 Based on Qt 5.6.0 (MSVC 2013, 32 bit) Built on Mar 14 2016 09:57:09 From revision d502727b2c Copyright 2008-2016 The Qt Company Ltd. All rights reserved. The program is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
It has
Desktop Qt 5.6.0 MSVC2013 64bit (default)
under the Build&Run/Kits
Compiler is set toMicrosoft Visual C++ Compiler 12.0 (amd64)
. -
@nulluse
Hm. It should've worked. As far as I remember VS 2013 should support most of the C++11 features. Could you post the full compile line for the file you're getting the error at?PS.
Also try declaring the variables for the capture explicitly and see how it goes:int x0 = widget.spX0->value(), y0 = widget.spY0->value(); auto func = [ x0, y0] (int& iteration) -> int { // 102 return iteration; };
-
14:41:29: Running steps for project MandelbrotQt... 14:41:29: Configuration unchanged, skipping qmake step. 14:41:29: Starting: "C:\Qt\Tools\QtCreator\bin\jom.exe" C:\Qt\Tools\QtCreator\bin\jom.exe -f Makefile.Debug cl -c -nologo -Zc:wchar_t -FS -Zi -MDd -GR -W3 -w34100 -w34189 -w44996 -EHsc /Fddebug\MandelbrotQt.pdb -DUNICODE -DWIN32 -DWIN64 -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I..\..\MandelbrotQt -I. -IC:\Qt\5.6\msvc2013_64\include -IC:\Qt\5.6\msvc2013_64\include\QtWidgets -IC:\Qt\5.6\msvc2013_64\include\QtGui -IC:\Qt\5.6\msvc2013_64\include\QtANGLE -IC:\Qt\5.6\msvc2013_64\include\QtCore -Idebug -I. -IC:\Qt\5.6\msvc2013_64\mkspecs\win32-msvc2013 -Fodebug\ @C:\Users\user0\AppData\Local\Temp\newform.obj.11028.16.jom newform.cpp ..\..\MandelbrotQt\newform.cpp(97) : error C2143: syntax error : missing ']' before '=' ..\..\MandelbrotQt\newform.cpp(97) : error C3481: 'x0': lambda capture variable not found ..\..\MandelbrotQt\newform.cpp(102) : error C2059: syntax error : ']' ..\..\MandelbrotQt\newform.cpp(97) : error C2059: syntax error : '=' ..\..\MandelbrotQt\newform.cpp(102) : error C2143: syntax error : missing ';' before '{' ..\..\MandelbrotQt\newform.cpp(105) : error C2065: 'x0' : undeclared identifier
Interesting enough, I started re-factoring the project to move the computations out of the GUI class, and my new class compiles fine when all I capture is
[this]
, then refer to the member variables inside the lambda's body.PS: Your workaround works. I will wrap that with
#if defined (Q_OS_WIN)
etc.PPS: But now I am getting lots of linker errors similar to this:
newform.obj:-1: error: LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl QtConcurrent::ThreadEngineBase::ThreadEngineBase(void)" (__imp_??0ThreadEngineBase@QtConcurrent@@QEAA@XZ) referenced in function "public: __cdecl QtConcurrent::IterateKernel<int *,void>::IterateKernel<int *,void>(int *,int *)" (??0?$IterateKernel@PEAHX@QtConcurrent@@QEAA@PEAH0@Z)
Do I need to add linking against a library when working under Windows?
PPPS: This does not make any sense: I am editing the
.pro
file adding and removingconcurrent
from QT but still getting this line in the output every time:15:01:05: Configuration unchanged, skipping qmake step.
-
@nulluse said:
But now I am getting lots of linker errors similar to this:
Do I need to add linking against a library when working under Windows?Only to the Qt modules as far as I know.
Qt += core gui widgets concurrent
etc. It should be working out of the box. -
See my last update - adding
QT += concurrent
does not change anything as the project thinks configuration is not changing. -
@nulluse
Sometimes the IDE is not as smart and it doesn't understand the.pro
has changed. Runqmake
explicitly (somewhere in the build menu) and do a rebuild after that. -
Forcing rebuild does not change anything. The pro file looks like this now:
#------------------------------------------------- # # Project created by QtCreator 2016-04-18T13:54:41 # #------------------------------------------------- QT += core gui concurrent greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = MandelbrotQt TEMPLATE = app SOURCES += main.cpp\ newform.cpp \ helpers/fileHelper.cpp \ mandelbrot/mandelbrot.cpp HEADERS += newform.h \ helpers/fileHelper.h \ mandelbrot/mandelbrot.h \ ui_newForm.h FORMS += newform.ui LIBS += -lQt5Concurrent CONFIG += c++11
The linker is still complaining.
-
@nulluse
It looks okay to me, with the only exception of this line:LIBS += -lQt5Concurrent
. You shouldn't need to pass that to the linker, adding theQT += concurrent
is enough (qmake
will generate the appropriate include files and linker switches). -
Running qmake fixed it!