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
QtWS25 Last Chance

Predefined TextFile as to replace Input Widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 969 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 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

    jsulmJ 1 Reply Last reply
    0
    • S Shahmisufi

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on 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
      2
      • Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on 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
        3
        • jsulmJ jsulm

          @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 last edited by
          #4

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

          1 Reply Last reply
          1
          • Pradeep KumarP Pradeep Kumar

            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 last edited by
            #5

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

            1 Reply Last reply
            1

            • Login

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