Results 1 to 12 of 12

Thread: How to display text from a file to a text browser

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to display text from a file to a text browser

    Hi all!
    I am attempting to read text from a .csv file and then count the umber of words and display the line and then word count. I can get it to work in a console application in c++ (n linux) but when I put that same code into Qt -- it won't display in the object browser.

    Here is my code below:

    Qt Code:
    1. #include<iostream>
    2. #include<cstdio>
    3. #include<fstream>
    4. #include<string>
    5. #include "bible.h"
    6. #include "ui_bible.h"
    7.  
    8. unsigned int numWords = 0;
    9.  
    10. bible::bible(QWidget *parent) :
    11. QMainWindow(parent),
    12. ui(new Ui::bible)
    13. {
    14. ui->setupUi(this);
    15. connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_textBrowser_historyChanged()));
    16. }
    17.  
    18. bible::~bible()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void bible::on_comboBox_activated(const QString &arg1)
    24. {
    25.  
    26. }
    27.  
    28. void bible::on_pushButton_clicked()
    29. {
    30. std::ifstream in("example.csv");
    31. if(not in)
    32. {
    33. perror("example.csv");
    34. }
    35. else
    36. {
    37. std::string text;
    38. //unsigned int numWords = 0;
    39. //unsigned int revnumWords = text.size();
    40. getline(in, text);
    41. std::cout << "Text: \"" << text << "\"" << std::endl;
    42. for(int i=0; i < text.size(); i++)
    43. {
    44. if(text[i] == ' ' || text[i] == '.' || text[i] == ',' ||
    45. text[i] == '!' || text[i] == '?' || text[i] == ';')
    46. {
    47. ++numWords;
    48. //--revnumWords;
    49. //cout << revnumWords << " ";
    50.  
    51. if (numWords > 8)
    52.  
    53. {
    54. std::cout << numWords + 12 << " ";
    55. //cout << revnumWords << " ";
    56.  
    57. }
    58.  
    59. else
    60. {
    61. std::cout << numWords + 10 << " ";
    62. //cout << revnumWords << " ";
    63. }
    64.  
    65. }
    66.  
    67. }
    68.  
    69. }
    70.  
    71. }
    72.  
    73.  
    74. void bible::on_textBrowser_historyChanged()
    75. {
    76. if (numWords > 8)
    77.  
    78. {
    79. std::cout << numWords + 12 << " ";
    80. //cout << revnumWords << " ";
    81.  
    82. }
    83.  
    84. else
    85. {
    86. std::cout << numWords + 10 << " ";
    87. //cout << revnumWords << " ";
    88. }
    89.  
    90. }
    To copy to clipboard, switch view to plain text mode 

    Any help would be greatly appreciated.

    ironmantis7x
    Last edited by wysota; 11th June 2012 at 12:01. Reason: missing [code] tags

Similar Threads

  1. Replies: 1
    Last Post: 18th October 2011, 11:02
  2. display in text browser
    By mecrazycoder in forum Newbie
    Replies: 7
    Last Post: 13th December 2010, 16:49
  3. Replies: 0
    Last Post: 2nd August 2010, 09:37
  4. Replies: 3
    Last Post: 3rd May 2009, 08:58
  5. Replies: 1
    Last Post: 3rd September 2008, 14:16

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
  •  
Qt is a trademark of The Qt Company.