依据报如下错误: audio_out = QAudioDeviceInfo(devtxt) TypeError: arguments did not match any overloaded call: QAudioDeviceInfo(): too many arguments QAudioDeviceInfo(QAudioDeviceInfo): argument 1 has unexpected type 'str'
时间: 2023-06-09 09:07:44 浏览: 87
这个错误的原因是你在调用 QAudioDeviceInfo(devtxt) 的时候传递了一个字符串类型的参数,而实际上它需要的参数类型是 QAudioDeviceInfo 类型。你可以使用 QAudioDeviceInfo::availableDevices(QAudio::Mode mode) 方法来获取可用的音频设备列表,并从中选择一个合适的设备来创建 QAudioDeviceInfo 对象。具体的实现方式可以参考 Qt 官方文档以及相关的例子。
相关问题
TypeError: arguments did not match any overloaded call: QStandardItemModel(parent: typing.Optional[QObject] = None): argument 1 has unexpected type 'int' QStandardItemModel(rows: int, columns: int, parent: typing.Optional[QObject] = None): not enough arguments
这个错误是因为你在创建 QStandardItemModel 时,传递的参数类型与该函数所接受的参数类型不匹配。根据错误提示,QStandardItemModel 可以接受两种不同类型的参数:
1. 不传递参数,即使用默认参数。此时 QStandardItemModel 会以 None 作为 parent 参数创建一个空模型。
2. 传递 rows 和 columns 参数来指定模型的行数和列数,可以同时传递 parent 参数。
你的错误提示显示,你传递了一个 int 类型的参数,这个参数并不是 QStandardItemModel 所接受的任何一种参数类型。请确保你传递的参数类型与 QStandardItemModel 所需的参数类型匹配。
TypeError: arguments did not match any overloaded call: start(self, QRunnable, priority: int = 0): argument 1 has unexpected type 'QThread' start(self, Callable[[], None], priority: int = 0): argument 1 has unexpected type 'QThread'怎么解决?
这个错误提示是因为你在调用 `start()` 方法时传入了一个 `QThread` 对象,但是 `start()` 方法的参数类型不匹配。
`start()` 方法有两个重载版本,一个是接受一个 `QRunnable` 对象作为参数,另一个是接受一个没有参数的可调用对象 `Callable[[], None]` 作为参数。
你需要根据你的需求选择正确的参数类型传入 `start()` 方法。如果你想要启动一个线程,可以通过创建一个 `QThread` 对象,将你的线程逻辑实现为一个 `QRunnable` 对象,然后将 `QRunnable` 对象传入 `start()` 方法来启动线程。
以下是一个示例代码:
```python
import sys
from PyQt5.QtCore import QRunnable, QThreadPool
class MyRunnable(QRunnable):
def run(self):
# 线程逻辑实现
print("Hello from thread")
if __name__ == '__main__':
app = QApplication(sys.argv)
runnable = MyRunnable()
QThreadPool.globalInstance().start(runnable)
sys.exit(app.exec_())
```
如果你想要启动一个没有参数的可调用对象,可以将该对象传入 `start()` 方法。以下是一个示例代码:
```python
import sys
from PyQt5.QtCore import QThreadPool
def my_function():
# 线程逻辑实现
print("Hello from thread")
if __name__ == '__main__':
app = QApplication(sys.argv)
QThreadPool.globalInstance().start(my_function)
sys.exit(app.exec_())
```
希望这些示例代码可以帮助你解决问题。