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. How to read specific word from a Text file in Qt ?
Forum Updated to NodeBB v4.3 + New Features

How to read specific word from a Text file in Qt ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 636 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.
  • P Offline
    P Offline
    Pappu Kumar Keshari
    wrote on last edited by
    #1

    From a text file I have to read only 3.2 from 3rd (version) line how can I read ?
    My Text file contains : ->
    File : 123
    IP : 192.67.7.45
    version : 3.2
    Latest : 3.4.6
    when I am using this code then it is showing output as -> "version : 3.2" But I need only 3.2 as a output

    QFile file("C:/Users/PAPPU KUMAR KESHARI/OneDrive/Desktop/Pappu123.txt");
    if (!file.open(QFile::ReadOnly | QFile::Text)) {
    QMessageBox::warning(this,"title","file not open");
    }

    QTextStream in(&file);
    QString text;
    while (!in.atEnd()) {
        text = in.readLine();
        if (text.contains("version"))
           break;
    }
    qDebug() << text;
    file.close();
    

    Please suggest me and need any improvement in my code then please do it .

    Christian EhrlicherC P 2 Replies Last reply
    0
    • P Pappu Kumar Keshari

      From a text file I have to read only 3.2 from 3rd (version) line how can I read ?
      My Text file contains : ->
      File : 123
      IP : 192.67.7.45
      version : 3.2
      Latest : 3.4.6
      when I am using this code then it is showing output as -> "version : 3.2" But I need only 3.2 as a output

      QFile file("C:/Users/PAPPU KUMAR KESHARI/OneDrive/Desktop/Pappu123.txt");
      if (!file.open(QFile::ReadOnly | QFile::Text)) {
      QMessageBox::warning(this,"title","file not open");
      }

      QTextStream in(&file);
      QString text;
      while (!in.atEnd()) {
          text = in.readLine();
          if (text.contains("version"))
             break;
      }
      qDebug() << text;
      file.close();
      

      Please suggest me and need any improvement in my code then please do it .

      Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Pappu-Kumar-Keshari said in How to read specific word from a Text file in Qt ?:

      "version : 3.2" But I need only 3.2 as a output

      Take a look at the split() functions of QString and also the search functions.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • P Pappu Kumar Keshari

        From a text file I have to read only 3.2 from 3rd (version) line how can I read ?
        My Text file contains : ->
        File : 123
        IP : 192.67.7.45
        version : 3.2
        Latest : 3.4.6
        when I am using this code then it is showing output as -> "version : 3.2" But I need only 3.2 as a output

        QFile file("C:/Users/PAPPU KUMAR KESHARI/OneDrive/Desktop/Pappu123.txt");
        if (!file.open(QFile::ReadOnly | QFile::Text)) {
        QMessageBox::warning(this,"title","file not open");
        }

        QTextStream in(&file);
        QString text;
        while (!in.atEnd()) {
            text = in.readLine();
            if (text.contains("version"))
               break;
        }
        qDebug() << text;
        file.close();
        

        Please suggest me and need any improvement in my code then please do it .

        P Offline
        P Offline
        Pappu Kumar Keshari
        wrote on last edited by
        #3

        @Pappu-Kumar-Keshari .. At which place I have to add in my code. Please suggest

        Christian EhrlicherC 1 Reply Last reply
        0
        • P Pappu Kumar Keshari

          @Pappu-Kumar-Keshari .. At which place I have to add in my code. Please suggest

          Christian EhrlicherC Online
          Christian EhrlicherC Online
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Pappu-Kumar-Keshari said in How to read specific word from a Text file in Qt ?:

          Please suggest

          Why should I write code for you? You know when the string contains version so use this string and split it up...

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          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