QtConcurrent::run errors with Qt6
-
Hi and welcome to devnet,
From a quick look at the documentation, you are not passing the arguments in the correct order. You need pass the member method first and then the rest of the parameters.
-
If I enter the right form
ThreadAssembly.setFuture(QtConcurrent::run(&cEncodeVideo::Assembly,this,Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue));
I get this error
engine/_EncodeVideo.cpp:930:55: required from here /usr/include/x86_64-linux-gnu/qt6/QtConcurrent/qtconcurrentstoredfunctioncall.h:189:64: error: static assertion failed: The first argument of passed callable object isn't a QPromise<T> & type. Did you intend to pass a callable which takes a QPromise<T> & type as a first argument? Otherwise it's not possible to invoke the function with passed arguments.
-
Can you provide a minimal example that shows that issue ?
It will be easier to check what might be going wrong. -
_EncodeVideo.cpp
bool cEncodeVideo::DoEncode() { ... if ((!PreviousFrame)||(PreviousFrame->RenderedImage.isNull())) ThreadAssembly.setFuture(QtConcurrent::run(&cEncodeVideo::Assembly,this,Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)); ... } void cEncodeVideo::Assembly(cDiaporamaObjectInfo *Frame,cDiaporamaObjectInfo *PreviousFrame,cSoundBlockList *RenderMusic,cSoundBlockList *ToEncodeMusic,bool &Continue) { ... }
-
Is cEncodeVideo::Assembly a member function?
Not sure QtConcurrent::run is able to bind together &cEncodeVideo::Assembly and the 'this' argument.
Try wrapping that part of the call into a lambda, or use std::mem_fn
Or some of the other arguments has a type mismatch. -
Is cEncodeVideo::Assembly a member function?
Not sure QtConcurrent::run is able to bind together &cEncodeVideo::Assembly and the 'this' argument.
Try wrapping that part of the call into a lambda, or use std::mem_fn
Or some of the other arguments has a type mismatch.@Asperamanca said in QtConcurrent::run errors with Qt6:
Is cEncodeVideo::Assembly a member function?
Not sure QtConcurrent::run is able to bind together &cEncodeVideo::Assembly and the 'this' argument.We do not know, because the OP has been asked to provide an example for us to check and they simply paste a couple of lines out of any context so nobody can tell....
-
In other files with QtConcurrent::run ffDiaporama 2.1 works well only not in _EncodeVideo.cpp.
gons@debian:~/Dokumente/_prog/_ffdiaporama/_qt6/_work_20250102/_work2/ffdiaporama-2.1$ find . -name '*' -type f -exec grep -q QtConcurrent::run {} \; -print ./src/ffDiaporama/wgt_QVideoPlayer/wgt_QVideoPlayer.cpp ./src/ffDiaporama/engine/_Diaporama.cpp ./src/ffDiaporama/engine/_EncodeVideo.cpp ./src/ffDiaporama/DlgExportProject/DlgExportProject.cpp ./src/ffDiaporama/DlgRenderVideo/DlgRenderVideo.cpp ./src/ffDiaporama/wgt_QMultimediaBrowser/QCustomFolderTable.cpp
-
It's a bit frustrating. You mention code we can't know, instead of providing sufficient source code to identify and name the problem (even when asked to do so).
I have given you leads on how to identify and fix the problem yourself, but you did not answer them. -
The code is here (ffDiaporama 2.1)
https://sourceforge.net/projects/ffdiaporama/files/ffdiaporama_bin_2.1.2014.0209.tar.gz
The translation in Qt6 is here
https://sourceforge.net/projects/ffdiaporama/files/qt6/ffdiaporama_2.1-1.diff.gz -
If I use
ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)}));
as solution corresponding to link text
I getengine/_EncodeVideo.cpp: In lambda function: engine/_EncodeVideo.cpp:930:89: error: invalid conversion from ‘const cSoundBlockList*’ to ‘cSoundBlockList*’ [-fpermissive] 930 | ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)})); | ^~~~~~~~~~~~ | | | const cSoundBlockList* engine/_EncodeVideo.h:126:111: note: initializing argument 3 of ‘void cEncodeVideo::Assembly(cDiaporamaObjectInfo*, cDiaporamaObjectInfo*, cSoundBlockList*, cSoundBlockList*, bool&)’ 126 | void Assembly(cDiaporamaObjectInfo *Frame,cDiaporamaObjectInfo *PreviousFrame,cSoundBlockList *RenderMusic,cSoundBlockList *ToEncodeMusic,bool &Continue); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~ engine/_EncodeVideo.cpp:930:102: error: invalid conversion from ‘const cSoundBlockList*’ to ‘cSoundBlockList*’ [-fpermissive] 930 | ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)})); | ^~~~~~~~~~~~~~ | | | const cSoundBlockList* engine/_EncodeVideo.h:126:140: note: initializing argument 4 of ‘void cEncodeVideo::Assembly(cDiaporamaObjectInfo*, cDiaporamaObjectInfo*, cSoundBlockList*, cSoundBlockList*, bool&)’ 126 | void Assembly(cDiaporamaObjectInfo *Frame,cDiaporamaObjectInfo *PreviousFrame,cSoundBlockList *RenderMusic,cSoundBlockList *ToEncodeMusic,bool &Continue); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ engine/_EncodeVideo.cpp:930:117: error: binding reference of type ‘bool&’ to ‘const bool’ discards qualifiers 930 | ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)})); | ^~~~~~~~ engine/_EncodeVideo.h:126:160: note: initializing argument 5 of ‘void cEncodeVideo::Assembly(cDiaporamaObjectInfo*, cDiaporamaObjectInfo*, cSoundBlockList*, cSoundBlockList*, bool&)’ 126 | void Assembly(cDiaporamaObjectInfo *Frame,cDiaporamaObjectInfo *PreviousFrame,cSoundBlockList *RenderMusic,cSoundBlockList *ToEncodeMusic,bool &Continue); | ~~~~~~^~~~~~~~ engine/_EncodeVideo.cpp: In member function ‘bool cEncodeVideo::DoEncode()’: engine/_EncodeVideo.cpp:930:56: error: use of deleted function ‘cSoundBlockList::cSoundBlockList(const cSoundBlockList&)’ 930 | ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)})); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
If I use
ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)}));
as solution corresponding to link text
I getengine/_EncodeVideo.cpp: In lambda function: engine/_EncodeVideo.cpp:930:89: error: invalid conversion from ‘const cSoundBlockList*’ to ‘cSoundBlockList*’ [-fpermissive] 930 | ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)})); | ^~~~~~~~~~~~ | | | const cSoundBlockList* engine/_EncodeVideo.h:126:111: note: initializing argument 3 of ‘void cEncodeVideo::Assembly(cDiaporamaObjectInfo*, cDiaporamaObjectInfo*, cSoundBlockList*, cSoundBlockList*, bool&)’ 126 | void Assembly(cDiaporamaObjectInfo *Frame,cDiaporamaObjectInfo *PreviousFrame,cSoundBlockList *RenderMusic,cSoundBlockList *ToEncodeMusic,bool &Continue); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~ engine/_EncodeVideo.cpp:930:102: error: invalid conversion from ‘const cSoundBlockList*’ to ‘cSoundBlockList*’ [-fpermissive] 930 | ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)})); | ^~~~~~~~~~~~~~ | | | const cSoundBlockList* engine/_EncodeVideo.h:126:140: note: initializing argument 4 of ‘void cEncodeVideo::Assembly(cDiaporamaObjectInfo*, cDiaporamaObjectInfo*, cSoundBlockList*, cSoundBlockList*, bool&)’ 126 | void Assembly(cDiaporamaObjectInfo *Frame,cDiaporamaObjectInfo *PreviousFrame,cSoundBlockList *RenderMusic,cSoundBlockList *ToEncodeMusic,bool &Continue); | ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~ engine/_EncodeVideo.cpp:930:117: error: binding reference of type ‘bool&’ to ‘const bool’ discards qualifiers 930 | ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)})); | ^~~~~~~~ engine/_EncodeVideo.h:126:160: note: initializing argument 5 of ‘void cEncodeVideo::Assembly(cDiaporamaObjectInfo*, cDiaporamaObjectInfo*, cSoundBlockList*, cSoundBlockList*, bool&)’ 126 | void Assembly(cDiaporamaObjectInfo *Frame,cDiaporamaObjectInfo *PreviousFrame,cSoundBlockList *RenderMusic,cSoundBlockList *ToEncodeMusic,bool &Continue); | ~~~~~~^~~~~~~~ engine/_EncodeVideo.cpp: In member function ‘bool cEncodeVideo::DoEncode()’: engine/_EncodeVideo.cpp:930:56: error: use of deleted function ‘cSoundBlockList::cSoundBlockList(const cSoundBlockList&)’ 930 | ThreadAssembly.setFuture(QtConcurrent::run([=]{Assembly(Frame,PreviousFrame,&RenderMusic,&ToEncodeMusic,Continue)})); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@mpvx
Here is what I would recommend you to do:- Create a static dummy function without parameters
- Test whether calling QtConcurrent::run with that dummy function works
- Create a member dummy function without parameters
- Test whether you can call them
- One by one, start adding your parameters to the dummy function. It does not need to do anything with them, just accept them
- Find out at which point the code no longer compiles
If, at that point, you cannot figure out what exactly the problem is, post
- your dummy function
- the code that calls the dummy function
-
It looks like Qt6’s QtConcurrent::run no longer supports passing a raw pointer to a member function the way Qt5 did. You’ll need to use a lambda or std::bind to wrap the member function call. For example:
ThreadAssembly.setFuture(QtConcurrent::run(= {
this->Assembly(Frame, PreviousFrame, &RenderMusic, &ToEncodeMusic, Continue);
}));
This way, the function becomes a callable object compatible with Qt6’s QtConcurrent::run. It should fix the operator() / ArgResolver errors you’re seeing.