D:\WorkSoftware\Qt\Qt5.12.12\5.12.12\msvc2015_64\include\QtCore\qobject.h:254: error: C2664: “QMetaObject::Connection QObject::connectImpl(const QObject *,void **,const QObject *,void **,QtPrivate::QSlotObjectBase *,Qt::ConnectionType,const int *,const QMetaObject *)”: 无法将参数 3 从“const QFuture<void> *”转换为“const QObject *” D:\WorkSoftware\Qt\Qt5.12.12\5.12.12\msvc2015_64\include\QtCore/qobject.h(254): note: 与指向的类型无关;转换要求 reinterpret_cast、C 样式转换或函数样式转换 mainwindow.cpp(14): note: 参见对正在编译的函数 模板 实例化“QMetaObject::Connection QObject::connect<void(__cdecl MainWindow::* )(void),void(__cdecl QFuture<void>::* )(void)>(const MainWindow *,Func1,const QFuture<void> *,Func2,Qt::ConnectionType)”的引用 with [ Func1=void (__cdecl MainWindow::* )(void), Func2=void (__cdecl QFuture<void>::* )(void) ]
时间: 2023-03-04 08:01:35 浏览: 179
It looks like you're encountering a compilation error in your C++ code. The error message indicates that there is a problem with a call to the `QObject::connect()` function.
The error message suggests that you're trying to connect a signal from a `QFuture<void>` object to a slot in a `MainWindow` object. However, the third argument to `connect()` should be a pointer to a `QObject`, not a `QFuture<void>` object.
To resolve this error, you'll need to change the third argument to `connect()` to be a pointer to a `QObject` object that emits the signal you're trying to connect. If the signal is emitted by the `QFuture<void>` object, you may need to create a separate `QObject` subclass to emit the signal on behalf of the `QFuture<void>` object.
Alternatively, you may be able to use a lambda expression to connect the signal and slot without needing to create a separate `QObject` subclass. Here's an example of how to use a lambda expression to connect a signal from a `QFuture<void>` object to a slot in a `MainWindow` object:
```
QFuture<void> future;
MainWindow mainWindow;
QObject::connect(&future, &QFuture<void>::finished, &mainWindow, [](){
// Slot code here
});
```
This connects the `finished` signal of the `QFuture<void>` object to a lambda function that contains the code for the slot. The lambda function is then connected to the `MainWindow` object using the `connect()` function.
阅读全文