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. #10
    Join Date
    Jun 2012
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11
    Thanks
    1

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

    Okay -- after some reading and coding, I cam up with the following:


    Qt Code:
    1. #include<iostream>
    2. #include<cstdio>
    3. #include<fstream>
    4. #include<string>
    5. #include "bible2.h"
    6. #include "ui_bible2.h"
    7.  
    8. using namespace std;
    9.  
    10. bible2::bible2(QWidget *parent) :
    11. QMainWindow(parent),
    12. ui(new Ui::bible2)
    13. {
    14. ui->setupUi(this);
    15. connect (ui->pushButton, SIGNAL(clicked()), this, SLOT(on_textEdit_textChanged()));
    16. }
    17.  
    18. bible2::~bible2()
    19. {
    20. delete ui;
    21. }
    22.  
    23. void bible2::on_pushButton_clicked()
    24. {
    25. ifstream in("example.csv");
    26. if(not in)
    27. {
    28. perror("example.csv");
    29. }
    30. else
    31. {
    32. string text;
    33. unsigned int numWords = 0;
    34. unsigned int revnumWords = 0;
    35. getline(in, text);
    36. cout << "Text: \"" << text << "\"" << endl;
    37. for(int i=0; i < text.size(); i++)
    38. {
    39. if(text[i] == ' ' || text[i] == '.' || text[i] == ',' ||
    40. text[i] == '!' || text[i] == '?' || text[i] == ';')
    41. {
    42. ++numWords;
    43. //cout << numWords + 10 << " ";
    44.  
    45. if (numWords > 8)
    46.  
    47. {
    48. cout << numWords + 12 << " ";
    49.  
    50. }
    51.  
    52. else
    53. {
    54. cout << numWords + 10 << " ";
    55. }
    56.  
    57. }
    58.  
    59. }
    60. in.close();
    61. cout << "\n";
    62. cout << "In this textual file \"example.csv\" there exists " << numWords;
    63. cout << " words!"<< endl;
    64.  
    65. }
    66. //return 0;
    67. }
    68.  
    69. void bible2::on_textBrowser_historyChanged()
    70. {
    71.  
    72. }
    73.  
    74. void bible2::on_textEdit_textChanged()
    75. {
    76. void QTextEdit::append(const QString & text);
    77. }
    To copy to clipboard, switch view to plain text mode 
    I am STILL not getting the text to show up in the GUI window.

    What is wrong with my append statement?

    ironmantis7x
    Last edited by wysota; 14th June 2012 at 08:42. 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.