Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Predefined TextFile as to replace Input Widget

    General and Desktop
    3
    5
    717
    Loading More Posts
    • 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
      Shahmisufi last edited by

      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

      jsulm 1 Reply Last reply Reply Quote 0
      • jsulm
        jsulm Lifetime Qt Champion @Shahmisufi last edited by

        @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 Reply Quote 2
        • Pradeep Kumar
          Pradeep Kumar last edited by VRonin

          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 Reply Quote 3
          • S
            Shahmisufi @jsulm last edited by

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

            1 Reply Last reply Reply Quote 1
            • S
              Shahmisufi @Pradeep Kumar last edited by

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

              1 Reply Last reply Reply Quote 1
              • First post
                Last post