QLineEdit.setText(QString):参数1有意外类型'int'

时间:2022-03-28 23:04:40

So i made this little program that's supposed to tell you the java version but i got this error :

我做了一个小程序,它应该告诉你java的版本但是我得到了这个错误:

QLineEdit.setText(QString): argument 1 has unexpected type 'int'

QLineEdit.setText(QString):参数1有意外类型'int'

while trying to run it

在尝试运行它的时候。

the code :

代码:

import sys
import os
from PyQt4 import QtGui
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *


class java(QtGui.QMainWindow):
    def s(self):
        g = os.system("java -version")
        self.version.setText(g)

    def __init__(self, parent=None):
        super(java, self).__init__(parent)

        self.setMinimumSize(201, 82)
        self.setMaximumSize(201, 82)

        self.version = QLineEdit(self)
        self.version.setMinimumSize(181, 21)
        self.version.setMaximumSize(181, 21)
        self.version.setGeometry(QRect(10 ,10, self.width(), self.height()))

        self.fetch = QPushButton(self)
        self.fetch.setMinimumSize(181, 23)
        self.fetch.setMaximumSize(181, 23)
        self.fetch.setGeometry(QRect(10, 50, self.width(), self.height()))
        self.fetch.setText("Fetch version")

        self.fetch.clicked.connect(self.s)

if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    main = java()
    main.show()
    sys.exit(app.exec_())

1 个解决方案

#1


1  

The problem is with your method s, wherein you execute the os.system call.

问题在于您的方法s,其中执行操作系统。系统调用。

def s(self):
    g = os.system("java -version")
    self.version.setText(g)

The variable g here stores True or False, which is the output of the system call, and not the version of java

这里的变量g存储True或False,这是系统调用的输出,而不是java的版本。

To capture the outputted version, use subprocess module, as described here

要捕获输出的版本,请使用下面描述的子过程模块。

#1


1  

The problem is with your method s, wherein you execute the os.system call.

问题在于您的方法s,其中执行操作系统。系统调用。

def s(self):
    g = os.system("java -version")
    self.version.setText(g)

The variable g here stores True or False, which is the output of the system call, and not the version of java

这里的变量g存储True或False,这是系统调用的输出,而不是java的版本。

To capture the outputted version, use subprocess module, as described here

要捕获输出的版本,请使用下面描述的子过程模块。