How to read specific word from a Text file in Qt ?
-
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 outputQFile 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 .
-
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 outputQFile 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 .
@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.
-
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 outputQFile 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 .
@Pappu-Kumar-Keshari .. At which place I have to add in my code. Please suggest
-
@Pappu-Kumar-Keshari .. At which place I have to add in my code. Please suggest
@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
versionso use this string and split it up...