У меня туда примешан Чуток stl, а именно стринга std-шная, а так всё. Не верю я что она мне весь коленкор портит.
вот хедер:
window.h#ifndef WINDOW_H
#define WINDOW_H
#include <QMainWindow>
#include <QLabel>
#include <QTextEdit>
#include <fstream>
#include <string>
using namespace std;
class Window : public QMainWindow
{
Q_OBJECT
public:
Window(QWidget *parent = 0);
private slots:
void OpenFile();
void htmGenerator();
private:
QLabel *label1, *label3;
};
#endif // WINDOW_H
вот мой срр-шник от хедера:
window.cpp#include "window.h"
#include <QMenu>
#include <QMenuBar>
#include <QApplication>
#include <QFileDialog>
#include <QDesktopWidget>
#include <QString>
#include <QPushButton>
#include <QList>
#include <QFile>
#include <QTextStream>
string Data;
int numLines;
void center(QWidget &widget, int w, int h)
{
int x, y;
int screenWidth;
int screenHeight;
QDesktopWidget *desktop = QApplication::desktop();
screenWidth = desktop->width();
screenHeight = desktop->height();
x = (screenWidth - w) / 2;
y = (screenHeight - h) / 2;
widget.move( x, y );
}
Window::Window(QWidget *parent)
: QMainWindow(parent)
{
int WIDTH = 450, HEIGHT = 350;
setFixedSize(WIDTH,HEIGHT);
QPixmap openpix("pics/open.jpg");
QPixmap quitpix("pics/quit.jpg");
QAction *open = new QAction(openpix, "&Open", this);
open->setShortcut(tr("CTRL+O"));
QAction *quit = new QAction(quitpix, "&Close", this);
quit->setShortcut(tr("CTRL+Q"));
QMenu *file;
file = menuBar()->addMenu("&File");
file->addAction(open);
file->addSeparator();
file->addAction(quit);
label1 = new QLabel("0", this);
label1->setGeometry(5,20,450,30);
label1->setText("Current file: None");
QLabel *label2 = new QLabel("0",this);
label2->setGeometry(5,40,450,150);
label2->setWordWrap(true);
label2->setText("READ BEFORE USE!!\nFirst of all change the extencion of your !!*.PXL!! file to !!TXT!! and then click @file->open@, choose your renamed file and after that click @Generate htm file@, choose destination file and save. After that enjoy your HTM file with table!");
QPushButton *generate = new QPushButton("Generate htm file", this);
generate->setGeometry(150, 165, 150, 40);
label3 = new QLabel("0",this);
label3->setGeometry(5,210,450,60);
label3->setWordWrap(true);
label3->setText("Generated file: None");
center(*this, WIDTH,HEIGHT);
connect(open, SIGNAL(triggered()), this, SLOT(OpenFile()));
connect(quit, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(generate, SIGNAL(clicked()), this, SLOT(htmGenerator()));
}
void Window::OpenFile()
{
//QString fileName = QFileDialog::getOpenFileName(this, tr("Open File"),"",tr("TXT Files (*.txt)"));
QString fileName = QFileDialog::getOpenFileName(
this,
tr("open File"),
QDir::currentPath(),
tr("txt Files (*.txt)") );
if (fileName.isEmpty ()) {
return;
}
string name = fileName.toStdString();
int found=0;
found=name.find_last_of("/\\");
QString filenam = QString::fromStdString(name.substr(found+1));
label1->setText("Current file: "+filenam);
const char* fname;
fname = name.c_str();
ifstream in(fname,ios::in);
char ch;
int Lines=0;
Data="";
while (!in.eof())
{
ch = in.get();
if ((ch >= 32 && ch<=127) || ch == 10)
Data = Data + ch;
if (ch == 10) Lines++;
}
in.close();
numLines = Lines;
}
void Window::htmGenerator() //generates html file
{
QList<QString> Lines;
/*QString l;
label1->setText(l);*/
int start=0, length=0;
for (unsigned int i=0; i<Data.length(); i++)
{
char ch = Data[i];
length++;
if (ch == 10)
{
Lines << QString::fromStdString(Data.substr(start,length));
start = i;
length=0;
}
}
QString sfilename = QFileDialog::getSaveFileName(
this,
tr("Save to *.htm File"),
QDir::currentPath(),
tr("htm Files (*.htm);;html Files (*.html)") );
if (sfilename.isEmpty ()) {
return;
}
//QString l;
//label1->setText(sfilename.right(3));
QString h1=".htm";
QString h2=".html";
if (!sfilename.contains(h1, Qt::CaseInsensitive) && !sfilename.contains(h2, Qt::CaseInsensitive))
{sfilename = sfilename + h1;}
QFile htm(sfilename);
if (htm.open(QFile::ReadWrite))
{
QTextStream out(&htm);
const QString top = "<html>\n<body>\n<center>\n<font color=green face=ComicSansMS>";
const QString bottom = "</body>\n</html>";
const QString tablec ="\n</table>\n</center>\n";
const QString tableo = "</font>\n<table border=1 width=100%>";
const QString fline = "<tr>\n<td>Trial</td>\n<td>stimuli-OnsetError</td>\n<td>stimuli-OnsetTime</td>\n"\
"<td>choice-OnsetError</td>\n<td>choice-OnsetTime</td>\n<td>choice-Mouse-IsCorrect</td>\n"\
"<td>choice-Mouse-Responses</td>\n<td>choice-Mouse-ResponseTime</td>\n"\
"<td>TrialTable-Column1</td>\n<td>TrialTable-correct resposes</td>\n</tr>";
const QString tro ="<tr height=40>";
const QString trc ="</tr>";
const QString tdo ="<td><center>";
const QString tdc ="</center></td>";
const QString br ="<br>";
int correct=0;
out << top;
for(int i=0; i<Lines.size();i++)
{
if (Lines[i].contains("**")){/*Do Nothing*/}
else if (Lines[i].contains("SubjectName",Qt::CaseInsensitive))
{
out << "Subject Name: ";
out << Lines[i].remove("SubjectName^",Qt::CaseInsensitive) << br;
} else if (Lines[i].contains("SessionNumber^",Qt::CaseInsensitive))
{
out << "SessionNumber: ";
out << Lines[i].remove("SessionNumber^",Qt::CaseInsensitive) << br;
} else if (Lines[i].contains("ExperimentName^",Qt::CaseInsensitive))
{
out << "ExperimentName";
out << Lines[i].remove("ExperimentName^",Qt::CaseInsensitive) << br;
out << tableo << fline;
};
if (Lines[i].contains("Trial^",Qt::CaseInsensitive))
{
out<<tro<<tdo;
out<<Lines[i].remove("Trial^",Qt::CaseInsensitive);
out<<tdc;
} else if(Lines[i].contains("stimuli-OnsetError^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("stimuli-OnsetError^",Qt::CaseInsensitive);
out<<tdc;
} else if(Lines[i].contains("stimuli-OnsetTime^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("stimuli-OnsetTime^",Qt::CaseInsensitive);
out<<tdc;
} else if(Lines[i].contains("choice-OnsetError^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("choice-OnsetError^",Qt::CaseInsensitive);
out<<tdc;
} else if(Lines[i].contains("choice-OnsetTime^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("choice-OnsetTime^",Qt::CaseInsensitive);
out<<tdc;
} else if(Lines[i].contains("choice-Mouse-IsCorrect^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("choice-Mouse-IsCorrect^",Qt::CaseInsensitive);
if (Lines[i].contains("1")) correct++;
out<<tdc;
} else if(Lines[i].contains("choice-Mouse-Responses^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("choice-Mouse-Responses^",Qt::CaseInsensitive);
out<<tdc;
} else if(Lines[i].contains("choice-Mouse-ResponseTime^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("choice-Mouse-ResponseTime^",Qt::CaseInsensitive);
out<<tdc;
} else if(Lines[i].contains("TrialTable-Column1^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("TrialTable-Column1^",Qt::CaseInsensitive);
out<<tdc;
} else if(Lines[i].contains("TrialTable-correct resposes^",Qt::CaseInsensitive))
{
out<<tdo;
out<<Lines[i].remove("TrialTable-correct resposes^",Qt::CaseInsensitive);
out<<tdc<<trc;
}
}
out << tablec;
out << "\n<center>\n<font color=green size=20 face=ComicSansMS>\nNumber of correct ansvers: ";
out << QString::number(correct,10);
out << "</center></font>";
out << bottom;
}
htm.close();
label3->setText("Generated file: "+sfilename);
}