Important: Please read the Qt Code of Conduct -

Predefined TextFile as to replace Input Widget

  • It is normal in GUI, where we will set an Input Widget (Scrollbar, slider, lineedit, etc) and will be controlled/ displayed to the Output Widget (ProgressBar, LCD, Label)

    Can I control the Output widget instead of using the Input widget, but I'm using a predefined text inside a textfile (.txt) which will be loaded inside the QT?


    I open the notepad, type in '60' , save as ".txt" file and execute my program. As it launches, the progress bar inside the widget will move to "60", or the LCD will display "60".

    Can anyone teach me how to do that?


  • Lifetime Qt Champion

    @Shahmisufi Take a look at QFile class. You can use it to read any files. So, open the file, read its content and put this content into your widget.

  • Hi,

    The sample code to get the read the data from text file and add the value to respective Output widgets

    Read the data from file and add it to QProgressbar or QLineEdit.

    void ClassProgram::getTextValue()
        QString data;
        QString fileName("./InputText.txt");
        QFile file(fileName);
        if(! {
            qDebug()<<"filenot opened"<<endl;
            qDebug()<<"file opened"<<endl;
            data = file.readAll();


  • @jsulm thank you, will look further upon your suggestion. :-)

  • @Pradeep-Kumar thanks for the assist! Will get to you if any matters arising ;-)

Log in to reply