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:
#include<iostream>
#include<cstdio>
#include<fstream>
#include<string>
#include "bible.h"
#include "ui_bible.h"
unsigned int numWords = 0;
ui(new Ui::bible)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_textBrowser_historyChanged()));
}
bible::~bible()
{
delete ui;
}
void bible
::on_comboBox_activated(const QString &arg1
) {
}
void bible::on_pushButton_clicked()
{
std::ifstream in("example.csv");
if(not in)
{
perror("example.csv");
}
else
{
std::string text;
//unsigned int numWords = 0;
//unsigned int revnumWords = text.size();
getline(in, text);
std::cout << "Text: \"" << text << "\"" << std::endl;
for(int i=0; i < text.size(); i++)
{
if(text[i] == ' ' || text[i] == '.' || text[i] == ',' ||
text[i] == '!' || text[i] == '?' || text[i] == ';')
{
++numWords;
//--revnumWords;
//cout << revnumWords << " ";
if (numWords > 8)
{
std::cout << numWords + 12 << " ";
//cout << revnumWords << " ";
}
else
{
std::cout << numWords + 10 << " ";
//cout << revnumWords << " ";
}
}
}
}
}
void bible::on_textBrowser_historyChanged()
{
if (numWords > 8)
{
std::cout << numWords + 12 << " ";
//cout << revnumWords << " ";
}
else
{
std::cout << numWords + 10 << " ";
//cout << revnumWords << " ";
}
}
#include<iostream>
#include<cstdio>
#include<fstream>
#include<string>
#include "bible.h"
#include "ui_bible.h"
unsigned int numWords = 0;
bible::bible(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::bible)
{
ui->setupUi(this);
connect(ui->pushButton, SIGNAL(clicked()), this, SLOT(on_textBrowser_historyChanged()));
}
bible::~bible()
{
delete ui;
}
void bible::on_comboBox_activated(const QString &arg1)
{
}
void bible::on_pushButton_clicked()
{
std::ifstream in("example.csv");
if(not in)
{
perror("example.csv");
}
else
{
std::string text;
//unsigned int numWords = 0;
//unsigned int revnumWords = text.size();
getline(in, text);
std::cout << "Text: \"" << text << "\"" << std::endl;
for(int i=0; i < text.size(); i++)
{
if(text[i] == ' ' || text[i] == '.' || text[i] == ',' ||
text[i] == '!' || text[i] == '?' || text[i] == ';')
{
++numWords;
//--revnumWords;
//cout << revnumWords << " ";
if (numWords > 8)
{
std::cout << numWords + 12 << " ";
//cout << revnumWords << " ";
}
else
{
std::cout << numWords + 10 << " ";
//cout << revnumWords << " ";
}
}
}
}
}
void bible::on_textBrowser_historyChanged()
{
if (numWords > 8)
{
std::cout << numWords + 12 << " ";
//cout << revnumWords << " ";
}
else
{
std::cout << numWords + 10 << " ";
//cout << revnumWords << " ";
}
}
To copy to clipboard, switch view to plain text mode
Any help would be greatly appreciated.
ironmantis7x
Bookmarks