Important: Please read the Qt Code of Conduct -

Execute command and display it problem

  • Dear all,

    I made simple "MainWindow" by QT with "push-button" and "Text Browser".

    Once I click on "push-button", execute a function which name is "Comm".

    Everything is working fine except the output is not displaying in "Text Browser"

    The Code

    from PyQt5.QtWidgets import *
    from PyQt5.uic import  *
    from os import path
    import sys
    import wmi
    FORM_CLASS,_ = loadUiType(path.join(path.dirname(__file__),"main2.ui"))
    class Ui_MainWindow(QMainWindow , FORM_CLASS):
        def __init__(self, parent=None):
        def Size_UI(self):
        def Buttons(self):
        def Comm(self):
            c = wmi.WMI ()
            for s in c.Win32_NetworkAdapter():
                if s.Manufacturer == "Intel" and s.Speed == "1000000000":
                    print ("The PC is " +s.SystemName +" and the Speed is 1GB ")
    def main():
        app = QApplication(sys.argv)
        window = Ui_MainWindow()
    if __name__ == '__main__':

    The output

    The PC is PCNAME and the Speed is 1GB

    I need this "output" to display on "text browser"

    Thanks in advance,

  • Lifetime Qt Champion

    Something like
    ui->textBrowser->setText("The PC is " +s.SystemName +" and the Speed is 1GB ");

  • @mrjj

    but it is not:

    ui->textBrowser->setPlainText("The PC is " +s.SystemName +" and the Speed is 1GB ");

    for QTextBrowser instead of:

    ui->textBrowser->setText("The PC is " +s.SystemName +" and the Speed is 1GB ");

  • Lifetime Qt Champion

    setPlainText is also fine.
    setText also work for non html text but will test to see if HTML format.
    Just use setPlainText if you have no plans for HTML.

  • Thanks for the ideas.

  • @Domenico Many thanks,

  • Solved!

     self.textBrowser.append("The PC is " +s.SystemName +" and the Speed is 1GB ")


Log in to reply