I have a such peace of code.

thread that reeds the file

Qt Code:
  1. #include <QThread>
  2. #include <QString>
  3. class openner : public QThread
  4. {
  5. Q_OBJECT
  6.  
  7. public:
  8. openner(QString);
  9. ~openner();
  10. void run();
  11. private:
  12. QString file;
  13. signals:
  14. void onStart(int);
  15. void on(int);
  16. void onEnd(int);
  17. };
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "openner.h"
  2. #include <QFile>
  3. #include <QTextStream>
  4. openner::openner(QString f)
  5. : QThread(0)
  6. {
  7. file=f;
  8. }
  9. void openner::run()
  10. {
  11. QString str;
  12. QFile f(file);
  13. f.open(QIODevice::ReadOnly | QIODevice::Text);
  14. QTextStream in(&f);
  15. emit onStart(f.size());
  16. while(!in.atEnd())
  17. {
  18. str=in.readLine();
  19. emit on(in.pos());
  20. }
  21. emit onEnd(f.size());
  22. f.close();
  23. }
  24. openner::~openner()
  25. {
  26.  
  27. }
To copy to clipboard, switch view to plain text mode 

main form

Qt Code:
  1. #include <QtGui/QMainWindow>
  2. #include <QProgressBar>
  3. #include "openner.h"
  4. class progressTest : public QMainWindow
  5. {
  6. Q_OBJECT
  7. private:
  8. openner *o;
  9. public:
  10. progressTest(QWidget *parent = 0, Qt::WFlags flags = 0);
  11. ~progressTest();
  12. protected slots:
  13. void onStart(int);
  14. void onProgres(int);
  15. void onEnd(int);
  16. };
To copy to clipboard, switch view to plain text mode 


Qt Code:
  1. #include "progresstest.h"
  2.  
  3. progressTest::progressTest(QWidget *parent, Qt::WFlags flags)
  4. : QMainWindow(parent, flags)
  5. {
  6. pb=new QProgressBar(this);
  7. pb->resize(200,20);
  8. o=new openner("C:\\projects\\umc\\UMC_invoice_.28532.00.00.100000_id_0793918_part_1.csv");
  9. QObject::connect(o,SIGNAL(onStart(int)),this,SLOT(onStart(int)));
  10. QObject::connect(o,SIGNAL(on(int)),this,SLOT(onProgres(int)));
  11. QObject::connect(o,SIGNAL(onEnd(int)),this,SLOT(onEnd(int)));
  12. o->start();
  13. }
  14. void progressTest::onStart(int m)
  15. {
  16. pb->setMaximum(m);
  17.  
  18. }
  19. void progressTest::onProgres(int l)
  20. {
  21. pb->setValue(l);
  22. }
  23. void progressTest::onEnd(int l)
  24. {
  25. pb->setValue(0);
  26. }
  27. progressTest::~progressTest()
  28. {
  29.  
  30. }
To copy to clipboard, switch view to plain text mode 


When I use my program with emit on(in.pos()); then it takes for about three hours to read file. But then I use it without emit on(in.pos()); file is read in the minutes. the size of file is 3000 kb
How the emit of signal can be optimised?
OS - windows XP
IDE - Microsoft Visual Studio 2008?