Getting a string out of QLineEdit

2019-08-30 04:39发布

问题:

I am quite new to the coding and have been just learning Python 3 and PyQt5 for several days. I am now coding a little prog for my friend who has to fill in very long forms for his job. I want the prog to write huge paragraphs of text for him, with him only entering the needed data.

Everything has been running perfectly well and I had no problems, but now I am just spending hours not being able to get how to turn a QLineEdit-piece into a string type of data.

Here is an extract of my code.

from PyQt5 import QtWidgets, QtCore
import sys

app = QtWidgets.QApplication(sys.argv)
window = QtWidgets.QWidget()
window.setWindowTitle("Fill-in-form")
window.resize(600, 600)
btnQuit = QtWidgets.QPushButton("Close the window")

label_a = QtWidgets.QLabel("Enter the driver's name")
label_a_a = QtWidgets.QLabel("Name:")
lineEdit_a_a = QtWidgets.QLineEdit()
str_1 = str(lineEdit_a_a) # here is the problem! the varible str_1 just wouldn't get the str-function.

set_5 = "kg, to the driver " 

main_body = (set_5+str_1) # accordingly, this doesn't make sense...


class MyClass(QtCore.QObject):
    def __init__(self):
        QtCore.QObject.__init__(self)
    @QtCore.pyqtSlot()
    def on_clicked(self):
        print(main_body) # ... and I don't get printed what I need. 

obj = MyClass()

btnCreateText = QtWidgets.QPushButton("Create text")
btnCreateText.clicked.connect(obj.on_clicked)

vbox = QtWidgets.QVBoxLayout()

vbox.addWidget(label_a)

vbox.addWidget(label_a_a)
vbox.addWidget(lineEdit_a_a)

vbox.addWidget(btnCreateText)
vbox.addWidget(btnQuit)

window.setLayout(vbox)
btnQuit.clicked.connect(app.quit)
window.show()
sys.exit(app.exec_())

I decided not to post the whole code as it is pretty long; however, from this code you will most probably understand what I am doing wrong.