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?
Example:
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?
Thanks
-
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?
Example:
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?
Thanks
@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(!file.open(QIODevice::ReadOnly)) { qDebug()<<"filenot opened"<<endl; } else { qDebug()<<"file opened"<<endl; data = file.readAll(); } file.close(); qDebug()<<data<<endl; m_progressBar->setValue(data.toInt()); m_lineEdit->setText(data); }
Thanks,
-
@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.
@jsulm thank you, will look further upon your suggestion. :-)
-
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(!file.open(QIODevice::ReadOnly)) { qDebug()<<"filenot opened"<<endl; } else { qDebug()<<"file opened"<<endl; data = file.readAll(); } file.close(); qDebug()<<data<<endl; m_progressBar->setValue(data.toInt()); m_lineEdit->setText(data); }
Thanks,
@Pradeep-Kumar thanks for the assist! Will get to you if any matters arising ;-)