0

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

QLineEdit.setText(QString): argument 1 has unexpected type '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_())
KinDa
  • 21
  • 1
  • 4

1 Answers1

1

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

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

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

Community
  • 1
  • 1
Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186