PyQt5 error: TypeError: arguments did not match any overloaded call

PyQt5 error: TypeError: arguments did not match any overloaded call

我的目标是用 PyQt5 制作一个网络浏览器,这是我的代码:

import sys
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *


class MainWindow(QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.browser = QWebEngineView()
        self.browser.setUrl(QUrl('https://www.google.com'))
        self.setCentralWidget(self.browser)
        self.showMaximized()
        navbar = QToolBar()
        self.addToolBar(navbar)

        back_btn = QAction('<=', self)
        back_btn.triggered.connect(self.browser.back)
        navbar.addAction(back_btn)

        forward_btn = QAction('=>', self)
        forward_btn.triggered.connect(self.browser.forward)
        navbar.addAction(forward_btn)
        reload_btn = QAction('reload', self)
        reload_btn.triggered.connect(self.browser.reload)
        navbar.addAction(reload_btn)

        self.url_bar = QLineEdit(self)
        navbar.addAction(self.url_bar)


APP = QApplication(sys.argv)
QApplication.setApplicationName('Kahari Go Web')
window = MainWindow()
APP.exec_()

但是当我 运行 我的代码时,我总是得到一个错误:

Traceback (most recent call last):
  File "D:\kahari Go Web\main.py", line 34, in <module>
    window = MainWindow()
  File "D:\kahari Go Web\main.py", line 29, in __init__
    navbar.addAction(self.url_bar)
TypeError: arguments did not match any overloaded call:
  addAction(self, QAction): argument 1 has unexpected type 'QLineEdit'
  addAction(self, str): argument 1 has unexpected type 'QLineEdit'
  addAction(self, QIcon, str): argument 1 has unexpected type 'QLineEdit'
  addAction(self, str, PYQT_SLOT): argument 1 has unexpected type 'QLineEdit'
  addAction(self, QIcon, str, PYQT_SLOT): argument 1 has unexpected type 'QLineEdit'

我唯一尝试的是浏览所有文章,但我无法理解它,所以我 运行 它在 repl.it 但 repl.it 无法导入 PyQt5。 我在 windows 10.

中使用 python 3.9 32 位

addAction() 用于添加 QAction 而不是小部件,如果要添加 QLineEdit 则必须使用 addWidget():

navbar.addWidget(self.url_bar)