Results 1 to 19 of 19

Thread: Qt creator 5

  1. #1
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    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:

    Qt Code:
    1. QString file_name1=QFileDialog::getOpenFileName(this,"open a file","C://");
    2. QFile file(file_name1);
    3.  
    4. if(!file.open(QFile::ReadOnly | QFile::Text))
    5. {
    6. QMessageBox::warning(this,"title","file not open");
    7. }
    8.  
    9. QTextStream in_stream1(&file);
    10. QString text= in_stream1.readAll();
    11.  
    12. QString file_name2=QFileDialog::getOpenFileName(this,"open a file","C://");
    13. QFile file1(file_name2);
    14. if(!file1.open(QFile::ReadOnly | QFile::Text))
    15. {
    16. QMessageBox::warning(this,"title","file not open");
    17. }
    18. QTextStream in_stream(&file1);
    19. QString text1=in_stream.readAll();
    20. //a=ui->plainTextEdit_3->setPlainText(text1);
    21. ui->plainTextEdit_3->setPlainText(QString::compare(text1,text1));
    To copy to clipboard, switch view to plain text mode 

    Added after 4 minutes:


    how to compare these two file pleaze help
    Last edited by anda_skoa; 1st November 2016 at 10:42. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    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,
    _

  3. #3
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    Quote Originally Posted by Anupamp View Post
    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.

    Quote Originally Posted by Anupamp View Post
    plzzzz help in qt creator
    This has nothing to do with QtCreator.

    Cheers,
    _

  5. #5
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    i want to extract the differences

    Quote Originally Posted by anda_skoa View Post
    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

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    Quote Originally Posted by Anupamp View Post
    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,
    _

  7. #7
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    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

    Quote Originally Posted by anda_skoa View Post
    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

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    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
    Qt Code:
    1. QVector<int> readValuesFromFile(const QString &filename);
    To copy to clipboard, switch view to plain text mode 

    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,
    _

  9. #9
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    Quote Originally Posted by anda_skoa View Post
    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
    Qt Code:
    1. QVector<int> readValuesFromFile(const QString &filename);
    To copy to clipboard, switch view to plain text mode 

    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
    ___

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    Quote Originally Posted by Anupamp View Post
    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?

    Quote Originally Posted by Anupamp View Post
    please give an example ...
    Yes, indeed, please do.

    Cheers,
    _

  11. #11
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    Quote Originally Posted by anda_skoa View Post
    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

  12. #12
    Join Date
    Aug 2015
    Posts
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Qt creator 5

    @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.

  13. #13
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    Quote Originally Posted by Anupamp View Post
    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,
    _

  14. #14
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    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
    ____

    Quote Originally Posted by anda_skoa View Post
    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
    ____

  15. #15
    Join Date
    Aug 2015
    Posts
    20
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Qt creator 5

    ... i have to calculate the difference between the two datas and show it
    what do you mean, maybe calculation as follows:

    Qt Code:
    1. variable A
    2. open first file
    3. 12 + 15 + 14 + 17 + 16 = xx
    4. A = xx
    5.  
    6. variable B
    7. open second file
    8. 5 + 10 + 4 + 12 + 5 = yy
    9. B = yy
    10.  
    11. A - B = ?
    To copy to clipboard, switch view to plain text mode 
    please explain

  16. The following user says thank you to kbsk007 for this useful post:

    Anupamp (8th November 2016)

  17. #16
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    Quote Originally Posted by Anupamp View Post
    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,
    _

  18. #17
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Qt creator 5

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  19. #18
    Join Date
    Nov 2016
    Posts
    17
    Thanks
    2
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    Quote Originally Posted by d_stranz View Post
    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_____

  20. #19
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Qt creator 5

    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,
    _

Similar Threads

  1. Replies: 10
    Last Post: 16th June 2014, 16:40
  2. Replies: 1
    Last Post: 12th June 2014, 08:37
  3. Replies: 2
    Last Post: 11th June 2014, 09:17
  4. Replies: 2
    Last Post: 22nd November 2011, 01:09
  5. QT creator
    By tertius in forum Newbie
    Replies: 7
    Last Post: 21st June 2010, 11:41

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.