error: no type named 'PromiseType' in 'struct QtPrivate::ArgResolver' 232 | ...

完整报错:

C:/Qt/Tools/mingw1120_64/bin/mingw32-make -f Makefile.Debug
mingw32-make[1]: Entering directory 'D:/study/C++/QT/build-compensator-emulator-Desktop_Qt_6_3_0_MinGW_64_bit-Debug'
g++ -c -fno-keep-inline-dllexport -g -std=gnu++1z -Wall -Wextra -Wextra -fexceptions -mthreads -DUNICODE -D_UNICODE -DWIN32 -DMINGW_HAS_SECURE_API=1 -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_SERIALPORT_LIB -DQT_CONCURRENT_LIB -DQT_CORE_LIB -DQT_NEEDS_QMAIN -I../compensator-emulator -I. -IC:/Qt/6.3.0/mingw_64/include -IC:/Qt/6.3.0/mingw_64/include/QtWidgets -IC:/Qt/6.3.0/mingw_64/include/QtGui -IC:/Qt/6.3.0/mingw_64/include/QtSerialPort -IC:/Qt/6.3.0/mingw_64/include/QtConcurrent -IC:/Qt/6.3.0/mingw_64/include/QtCore -Idebug -I. -I/include -IC:/Qt/6.3.0/mingw_64/mkspecs/win32-g++  -o debug/mainwindow.o ../compensator-emulator/mainwindow.cpp
../compensator-emulator/mainwindow.cpp: In member function 'void MainWindow::send(QSerialPort*)':
../compensator-emulator/mainwindow.cpp:33:36: warning: unused parameter 'serialPort' [-Wunused-parameter]
   33 | void MainWindow::send(QSerialPort *serialPort){
      |                       ~~~~~~~~~~~~~^~~~~~~~~~
In file included from C:/Qt/6.3.0/mingw_64/include/QtCore/qfuture.h:49,
                 from C:/Qt/6.3.0/mingw_64/include/QtCore/QtCore:96,
                 from C:/Qt/6.3.0/mingw_64/include/QtConcurrent/QtConcurrentDepends:3,
                 from C:/Qt/6.3.0/mingw_64/include/QtConcurrent/QtConcurrent:3,
                 from ../compensator-emulator/mainwindow.h:8,
                 from ../compensator-emulator/mainwindow.cpp:5:
C:/Qt/6.3.0/mingw_64/include/QtCore/qfuture_impl.h: In instantiation of 'struct QtPrivate::ArgResolver':
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:225:64:   required from 'struct QtConcurrent::PromiseTaskResolver'
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:247:8:   required from 'struct QtConcurrent::TaskResolverHelper, MainWindow*, void (MainWindow::*)(QSerialPort*), QSerialPort*>'
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:253:8:   required from 'struct QtConcurrent::TaskResolver'
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentrun.h:76:76:   required from 'auto QtConcurrent::run(QThreadPool*, Function&&, Args&& ...) [with Function = MainWindow*; Args = {void (MainWindow::*)(QSerialPort*), QSerialPort*}]'
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentrun.h:93:15:   required from 'auto QtConcurrent::run(Function&&, Args&& ...) [with Function = MainWindow*; Args = {void (MainWindow::*)(QSerialPort*), QSerialPort*}]'
../compensator-emulator/mainwindow.cpp:157:37:   required from here
C:/Qt/6.3.0/mingw_64/include/QtCore/qfuture_impl.h:214:43: error: 'operator()' is not a member of 'std::decay::type' {aka 'MainWindow*'}
  214 | struct ArgResolver : ArgResolver::operator())>
      |                                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtaskbuilder.h:45,
                 from C:/Qt/6.3.0/mingw_64/include/QtConcurrent/QtConcurrent:4,
                 from ../compensator-emulator/mainwindow.h:8,
                 from ../compensator-emulator/mainwindow.cpp:5:
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h: In instantiation of 'struct QtConcurrent::PromiseTaskResolver':
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:247:8:   required from 'struct QtConcurrent::TaskResolverHelper, MainWindow*, void (MainWindow::*)(QSerialPort*), QSerialPort*>'
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:253:8:   required from 'struct QtConcurrent::TaskResolver'
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentrun.h:76:76:   required from 'auto QtConcurrent::run(QThreadPool*, Function&&, Args&& ...) [with Function = MainWindow*; Args = {void (MainWindow::*)(QSerialPort*), QSerialPort*}]'
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentrun.h:93:15:   required from 'auto QtConcurrent::run(Function&&, Args&& ...) [with Function = MainWindow*; Args = {void (MainWindow::*)(QSerialPort*), QSerialPort*}]'
../compensator-emulator/mainwindow.cpp:157:37:   required from here
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:225:64: error: no type named 'IsPromise' in 'struct QtPrivate::ArgResolver'
  225 |     static_assert(QtPrivate::ArgResolver::IsPromise::value,
      |                                                                ^~~~~
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h: In instantiation of 'static auto QtConcurrent::PromiseTaskResolver::run(QtConcurrent::PromiseTaskResolver::TaskWithArgs&&, const QtConcurrent::TaskStartParameters&) [with Function = MainWindow*; Args = {void (MainWindow::*)(QSerialPort*), QSerialPort*}; QtConcurrent::PromiseTaskResolver::TaskWithArgs = std::tuple]':
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentrun.h:76:76:   required from 'auto QtConcurrent::run(QThreadPool*, Function&&, Args&& ...) [with Function = MainWindow*; Args = {void (MainWindow::*)(QSerialPort*), QSerialPort*}]'
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentrun.h:93:15:   required from 'auto QtConcurrent::run(Function&&, Args&& ...) [with Function = MainWindow*; Args = {void (MainWindow::*)(QSerialPort*), QSerialPort*}]'
../compensator-emulator/mainwindow.cpp:157:37:   required from here
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:231:15: error: no type named 'PromiseType' in 'struct QtPrivate::ArgResolver'
  231 |         using PromiseType = typename QtPrivate::ArgResolver::PromiseType;
      |               ^~~~~~~~~~~
C:/Qt/6.3.0/mingw_64/include/QtConcurrent/qtconcurrentstoredfunctioncall.h:232:17: error: no type named 'PromiseType' in 'struct QtPrivate::ArgResolver'
  232 |         return (new StoredFunctionCallWithPromise(std::move(args)))
      |                ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mingw32-make[1]: Leaving directory 'D:/study/C++/QT/build-compensator-emulator-Desktop_Qt_6_3_0_MinGW_64_bit-Debug'
mingw32-make[1]: *** [Makefile.Debug:1088: debug/mainwindow.o] Error 1
mingw32-make: *** [Makefile:45: debug] Error 2
11:00:40: 进程"C:\Qt\Tools\mingw1120_64\bin\mingw32-make.exe"退出,退出代码 2 。
Error while building/deploying project compensator-emulator (kit: Desktop Qt 6.3.0 MinGW 64-bit)
When executing step "Make"

引起上面报错的代码是:

QFuture readThd_ = QtConcurrent::run(this, &MainWindow::send, &m_serialPort_);

原因:
QtConcurrent::run使用类内成员函数作为线程方法时,Qt6以前上面的写法没有问,Qt6以后,就是下面这样的写法了:

QFuture readThd_ = QtConcurrent::run(&MainWindow::send, this, &m_serialPort_);

如果对您帮助,就请帮忙点个赞吧,赠人玫瑰手留余香!

参考链接:
https://forum.qt.io/topic/131033/qtconcurrent-compile-errors/4

你可能感兴趣的:(error: no type named 'PromiseType' in 'struct QtPrivate::ArgResolver' 232 | ...)