Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Predefined TextFile as to replace Input Widget
Forum Update on Monday, May 27th 2025

Predefined TextFile as to replace Input Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 982 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Shahmisufi
    wrote on 18 Oct 2016, 03:20 last edited by
    #1

    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

    J 1 Reply Last reply 18 Oct 2016, 04:11
    0
    • S Shahmisufi
      18 Oct 2016, 03:20

      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

      J Online
      J Online
      jsulm
      Lifetime Qt Champion
      wrote on 18 Oct 2016, 04:11 last edited by
      #2

      @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.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 18 Oct 2016, 08:18
      2
      • P Offline
        P Offline
        Pradeep Kumar
        wrote on 18 Oct 2016, 06:01 last edited by VRonin
        #3

        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
        Qt,QML Developer

        S 1 Reply Last reply 18 Oct 2016, 08:29
        3
        • J jsulm
          18 Oct 2016, 04:11

          @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.

          S Offline
          S Offline
          Shahmisufi
          wrote on 18 Oct 2016, 08:18 last edited by
          #4

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

          1 Reply Last reply
          1
          • P Pradeep Kumar
            18 Oct 2016, 06:01

            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,

            S Offline
            S Offline
            Shahmisufi
            wrote on 18 Oct 2016, 08:29 last edited by
            #5

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

            1 Reply Last reply
            1

            1/5

            18 Oct 2016, 03:20

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved