PDA

View Full Version : Qt creator 5



Anupamp
1st November 2016, 09:12
i am doing program to differwence the two notepad file but only one is showing and plese suggest me for the program in qt creator

Added after 45 minutes:


QString file_name1=QFileDialog::getOpenFileName(this,"open a file","C://");
QFile file(file_name1);

if(!file.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::warning(this,"title","file not open");
}

QTextStream in_stream1(&file);
QString text= in_stream1.readAll();

QString file_name2=QFileDialog::getOpenFileName(this,"open a file","C://");
QFile file1(file_name2);
if(!file1.open(QFile::ReadOnly | QFile::Text))
{
QMessageBox::warning(this,"title","file not open");
}
QTextStream in_stream(&file1);
QString text1=in_stream.readAll();
//a=ui->plainTextEdit_3->setPlainText(text1);
ui->plainTextEdit_3->setPlainText(QString::compare(text1,text1));

Added after 4 minutes:

how to compare these two file pleaze help

anda_skoa
1st November 2016, 09:43
What do you mean with "compare"?

Do you simply need to check if the strings are different or do you want to extract the differences?

Cheers,
_

Anupamp
1st November 2016, 13:44
Actually i have two note pad files containinhg some numbers
i have to subtract the string from one text to another
i am able to read the file but not able to subtract.


plzzzz help in qt creator

anda_skoa
1st November 2016, 14:40
Actually i have two note pad files containinhg some numbers
i have to subtract the string from one text to another
i am able to read the file but not able to subtract.

You don't appear to try to parse numbers.
Maybe you should start with that.



plzzzz help in qt creator
This has nothing to do with QtCreator.

Cheers,
_

Anupamp
2nd November 2016, 04:18
i want to extract the differences


What do you mean with "compare"?

Do you simply need to check if the strings are different or do you want to extract the differences?

Cheers,
_

i want to extract the differences

anda_skoa
2nd November 2016, 08:46
i want to extract the differences

The text differences? You mentioned numbers earlier and subtracting.

Can you give an example of the two file contents?

Cheers,
_

Anupamp
2nd November 2016, 11:29
one text containing
no of books 12 15 14 17 16
other txt also contain
no of books taken 05 10 04 12 05
then overall no of books rest ??

all these in the form of text format .txt


The text differences? You mentioned numbers earlier and subtracting.

Can you give an example of the two file contents?

Cheers,
_


one text containing
no of books 12 15 14 17 16
other txt also contain
no of books taken 05 10 04 12 05
then overall no of books rest ??

all these in the form of text format .txt

thanks in advance

anda_skoa
2nd November 2016, 12:09
Ah, ok.

I would recommend you start with a function that can handle a single file if given a file name and returns a vector of integers.

I.e. a method with a signature similar to


QVector<int> readValuesFromFile(const QString &filename);


Assuming your numbers are all separated by space characters you can probably process the file content like this
1) strip away the text, e.g. the "no of books" part
2) using QString::split() to get a list of number strings
3) create a vector with the same size
4) loop over the list and convert each number string into a numerical value, see QString::toInt().

Once you have that function you can easily call it for both files and then perform the difference calculation on the two vectors.

Cheers,
_

Anupamp
3rd November 2016, 06:12
Ah, ok.

I would recommend you start with a function that can handle a single file if given a file name and returns a vector of integers.

I.e. a method with a signature similar to


QVector<int> readValuesFromFile(const QString &filename);


Assuming your numbers are all separated by space characters you can probably process the file content like this
1) strip away the text, e.g. the "no of books" part
2) using QString::split() to get a list of number strings
3) create a vector with the same size
4) loop over the list and convert each number string into a numerical value, see QString::toInt().

Once you have that function you can easily call it for both files and then perform the difference calculation on the two vectors.

Cheers,
_
i am doing such things but it is not converted into strings the the data i.e "the no of books" is not separated by space it is in the form of excel form then??

please give an example ...


thanks in advance
___

anda_skoa
3rd November 2016, 08:19
i am doing such things but it is not converted into strings the the data i.e "the no of books" is not separated by space it is in the form of excel form then??

You wrote that you had two "notepad" files, which are text files.
Now you have Excel files?



please give an example ...

Yes, indeed, please do.

Cheers,
_

Anupamp
3rd November 2016, 10:28
You wrote that you had two "notepad" files, which are text files.
Now you have Excel files?


Yes, indeed, please do.

Cheers,
_


no it is a notepad file in the form of text the data is in the form like excel

kbsk007
3rd November 2016, 10:35
@Anupamp
I do not understand while you will discover again a wheel.
If you look in Internet then will find a lot programs that compare two files, even written in qt 4 and qt 5. Look for diff or diff3.

anda_skoa
3rd November 2016, 12:03
no it is a notepad file in the form of text the data is in the form like excel
Windows Notepad can only deal with text files, it can't open Excel files.

So, which is it.

Cheers,
_

Anupamp
4th November 2016, 06:08
i have two notepad files in which there are datas . the datas are numbers which is written vertically in both the text files i have to calculate the difference between the two datas and show it

this is what exactly i mean to say sir

thanks in advance
____


Windows Notepad can only deal with text files, it can't open Excel files.

So, which is it.

Cheers,
_
i have two notepad files in which there are datas . the datas are numbers which is written vertically in both the text files i have to calculate the difference between the two datas and show it

this is what exactly i mean to say sir

thanks in advance
____

kbsk007
4th November 2016, 07:46
... i have to calculate the difference between the two datas and show it
what do you mean, maybe calculation as follows:


variable A
open first file
12 + 15 + 14 + 17 + 16 = xx
A = xx

variable B
open second file
5 + 10 + 4 + 12 + 5 = yy
B = yy

A - B = ?
please explain

anda_skoa
4th November 2016, 10:07
i have two notepad files in which there are datas . the datas are numbers which is written vertically in both the text files i have to calculate the difference between the two datas and show it

Well, then comment #8 still mostly applies.
If the values are separate by newline instead of space, then use either that for the split operation or read line by line using QIODevice::readLine() or QTextStream::readLine().

Cheers,
_

d_stranz
4th November 2016, 15:26
This is sounding more and more like someone who is desperate to complete a homework assignment, but has no idea how to start and is unable to make a clear statement about what the goal is or even how the data are formatted in the two files. First everything was on one line, now it is "vertically". The OP can't explain whether he (I assume it is he) wants to just compare the two files and look for differences, convert the contents into integers and subtract each one, or maybe something else.

Maybe if he just posted the homework assignment, we could understand what the problem really is and give some advice on how to solve it. As it is now, we are just going in circles.

Anupamp
8th November 2016, 06:26
This is sounding more and more like someone who is desperate to complete a homework assignment, but has no idea how to start and is unable to make a clear statement about what the goal is or even how the data are formatted in the two files. First everything was on one line, now it is "vertically". The OP can't explain whether he (I assume it is he) wants to just compare the two files and look for differences, convert the contents into integers and subtract each one, or maybe something else.

Maybe if he just posted the homework assignment, we could understand what the problem really is and give some advice on how to solve it. As it is now, we are just going in circles.


Actually yes i have to complete homework assignment please help
assignment is :
there are two text files which contain numeric values in vertical form i.e upside down with the title. create a new text file with the difference of values


thanks in advance_____

anda_skoa
8th November 2016, 17:22
Then skipping the title is as easy as skipping the first line.

So suggestions from comment #8 but with line-by-line reading as suggested in comment #16.

Cheers,
_