#include <QThread>
#include <QMessageBox>
#include "qt_thread.h"
int a = 0;
int b = 0;
MyCalc *c;
{
}
void MyCalc::myLoop()
{
b = 0;
float tmp = 0.0;
while (b < 300000000){
tmp = 6.5192412518215212 * (tmp+1) / 2.6315211121893 + b * b;
b++;
if (! (b % 100000000) ){
emit incrementedB();
}
tmp = 0.0;
}
emit finishedLoop(); // report end of calculation
}
void Qt_Thread::updateMyB()
{
ui.
lbb->setText
( QString("%1").
arg(b
) );
}
Qt_Thread
::Qt_Thread(QWidget *parent
){
ui.setupUi(this);
t->start();
c = new MyCalc();
c->moveToThread(t);
connect(ui.pbWithThread, SIGNAL(clicked()), c, SLOT(myLoop()));
connect(c, SIGNAL(finishedLoop()),this, SLOT(afterLoop()));
connect(c, SIGNAL(incrementedB()), this, SLOT(updateMyB()) );
connect(ui.pbIncA, SIGNAL(clicked()), this, SLOT(pbIncAClicked()));
connect(ui.pbWithoutThread, SIGNAL(clicked()), this, SLOT(pbWithoutThreadClicked()));
}
void Qt_Thread::pbWithoutThreadClicked()
{
b = 0;
float tmp = 0.0;
while (b < 300000000){
tmp = 6.5192412518215212 * (tmp+1) / 2.6315211121893 + b * b;
b++;
if (! (b % 100000000) ){
ui.
lbb->setText
( QString("%1").
arg(b
) );
qApp->processEvents();
}
tmp = 0.0;
}
ui.lbb->setText( "Fertig :)" );
}
void Qt_Thread::pbWithThreadClicked()
{
}
void Qt_Thread::setb(const int b)
{
ui.
lbb->setText
( QString("%1").
arg(b
) );
}
void Qt_Thread::pbIncAClicked()
{
a++;
ui.
lba->setText
( QString("%1").
arg(a
) );
}
void Qt_Thread::afterLoop()
{
ui.lbb->setText("Fertig! :)");
}
Qt_Thread::~Qt_Thread()
{
}
#include <QThread>
#include <QMessageBox>
#include "qt_thread.h"
int a = 0;
int b = 0;
QThread *t;
MyCalc *c;
MyCalc::MyCalc(QObject* parent) :
QObject(parent)
{
}
void MyCalc::myLoop()
{
b = 0;
float tmp = 0.0;
while (b < 300000000){
tmp = 6.5192412518215212 * (tmp+1) / 2.6315211121893 + b * b;
b++;
if (! (b % 100000000) ){
emit incrementedB();
}
tmp = 0.0;
}
emit finishedLoop(); // report end of calculation
}
void Qt_Thread::updateMyB()
{
ui.lbb->setText( QString("%1").arg(b) );
}
Qt_Thread::Qt_Thread(QWidget *parent)
: QWidget(parent)
{
ui.setupUi(this);
t = new QThread();
t->start();
c = new MyCalc();
c->moveToThread(t);
connect(ui.pbWithThread, SIGNAL(clicked()), c, SLOT(myLoop()));
connect(c, SIGNAL(finishedLoop()),this, SLOT(afterLoop()));
connect(c, SIGNAL(incrementedB()), this, SLOT(updateMyB()) );
connect(ui.pbIncA, SIGNAL(clicked()), this, SLOT(pbIncAClicked()));
connect(ui.pbWithoutThread, SIGNAL(clicked()), this, SLOT(pbWithoutThreadClicked()));
}
void Qt_Thread::pbWithoutThreadClicked()
{
b = 0;
float tmp = 0.0;
while (b < 300000000){
tmp = 6.5192412518215212 * (tmp+1) / 2.6315211121893 + b * b;
b++;
if (! (b % 100000000) ){
ui.lbb->setText( QString("%1").arg(b) );
qApp->processEvents();
}
tmp = 0.0;
}
ui.lbb->setText( "Fertig :)" );
}
void Qt_Thread::pbWithThreadClicked()
{
}
void Qt_Thread::setb(const int b)
{
ui.lbb->setText( QString("%1").arg(b) );
}
void Qt_Thread::pbIncAClicked()
{
a++;
ui.lba->setText( QString("%1").arg(a) );
}
void Qt_Thread::afterLoop()
{
ui.lbb->setText("Fertig! :)");
}
Qt_Thread::~Qt_Thread()
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks