Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains in detail how this page works. To use all features of this page, you should consider registering. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.
|
|
Source code |
1 2 3 4 5 6 7 8 |
void MainWindow::on_btnStart_clicked()
{
this->ui.progressBar->show();
// ... long code here ...
this->ui.progressBar->hide();
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
MainWindow::MainWindow()
{
ui.setupUi(this);
this->ui.progressBar->setMinimum(0);
this->ui.progressBar->setMaximum(0);
this->ui.progressBar->hide();
}
void MainWindow::on_btnStop_clicked()
{
this->ui.progressBar->hide();
}
void MainWindow::on_btnStart_clicked()
{
this->ui.progressBar->show();
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
#ifndef BUTTONFORM_H
#define BUTTONFORM_H
#include "ui_main.h"
#include <QThread>
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow();
class ProgressThread : public QThread
{
public:
virtual void run();
QProgressBar* ProgressBar;
};
public slots:
void on_btnStart_clicked();
};
#endif
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include "form.h"
#include <iostream>
#include <cmath>
void MainWindow::ProgressThread::run()
{
this->ProgressBar->show();
}
MainWindow::MainWindow()
{
this->setupUi(this);
this->progressBar->setMinimum(0);
this->progressBar->setMaximum(0);
this->progressBar->hide();
}
void MainWindow::on_btnStart_clicked()
{
std::cout << "Clicked." << std::endl;
ProgressThread myThread;
myThread.ProgressBar = this->progressBar;
myThread.start();
myThread.wait();
for(unsigned int i = 0; i < 1e7; i++)
{
float a = sin(i);
}
this->progressBar->hide();
std::cout << "Done." << std::endl;
}
|
|
|
PHP Source code |
1 |
connect(this,SIGNAL(my_signal),this,SLOT(my_slot),Qt::QueuedConnection);
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
#ifndef BUTTONFORM_H
#define BUTTONFORM_H
#include "ui_main.h"
#include <QThread>
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow();
class ProgressThread : public QThread
{
public:
virtual void run();
signals:
void StartProgressSignal();
void StopProgressSignal();
};
ProgressThread myProgressThread;
public slots:
void on_btnStart_clicked();
void ProgressSlot();
};
#endif
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
#include "form.h"
#include <iostream>
#include <cmath>
void MainWindow::StartProgressSlot()
{
this->progressBar->show();
}
void MainWindow::StopProgressSlot()
{
this->progressBar->hide();
}
void MainWindow::ProgressThread::run()
{
emit StartProgressSignal();
}
MainWindow::MainWindow()
{
this->setupUi(this);
this->progressBar->setMinimum(0);
this->progressBar->setMaximum(0);
this->progressBar->hide();
connect(&myProgressThread, SIGNAL(StartProgressSignal()), this, SLOT(StartProgressSlot()), Qt::QueuedConnection);
connect(&myProgressThread, SIGNAL(StopProgressSignal()), this, SLOT(StopProgressSlot()), Qt::QueuedConnection);
}
void MainWindow::on_btnStart_clicked()
{
std::cout << "Clicked." << std::endl;
myProgressThread.start();
myProgressThread.wait();
for(unsigned int i = 0; i < 1e7; i++)
{
float a = sin(i);
}
std::cout << "Done." << std::endl;
}
|
It still doesn't display the progress bar during the loop execution!|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
#ifndef BUTTONFORM_H
#define BUTTONFORM_H
#include "ui_main.h"
#include <QThread>
class ProgressThread : public QThread
{
Q_OBJECT
public:
void run();
void exit();
signals:
void StartProgressSignal();
void StopProgressSignal();
};
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
MainWindow();
ProgressThread myProgressThread;
public slots:
void on_btnStart_clicked();
void StartProgressSlot();
void StopProgressSlot();
};
#endif
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
#include "form.h"
#include <iostream>
#include <cmath>
void MainWindow::StartProgressSlot()
{
this->progressBar->show();
}
void MainWindow::StopProgressSlot()
{
this->progressBar->hide();
}
void ProgressThread::run()
{
emit StartProgressSignal();
}
void ProgressThread::exit()
{
emit StopProgressSignal();
}
MainWindow::MainWindow()
{
this->setupUi(this);
this->progressBar->setMinimum(0);
this->progressBar->setMaximum(0);
this->progressBar->hide();
connect(&myProgressThread, SIGNAL(StartProgressSignal()), this, SLOT(StartProgressSlot()), Qt::QueuedConnection);
connect(&myProgressThread, SIGNAL(StopProgressSignal()), this, SLOT(StopProgressSlot()), Qt::QueuedConnection);
}
void MainWindow::on_btnStart_clicked()
{
std::cout << "Clicked." << std::endl;
myProgressThread.start();
for(unsigned int i = 0; i < 1e8; i++)
{
float a = sin(i);
}
std::cout << "Done." << std::endl;
myProgressThread.exit();
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
#include "form.h"
#include <iostream>
#include <cmath>
void MainWindow::StartProgressSlot()
{
this->progressBar->show();
}
void MainWindow::StopProgressSlot()
{
this->progressBar->hide();
}
void ProgressThread::run()
{
emit StartProgressSignal();
for(unsigned int i = 0; i < 1e8; i++)
{
float a = sin(i);
}
std::cout << "Done." << std::endl;
exit();
emit StopProgressSignal();
}
void ProgressThread::exit()
{
emit StopProgressSignal();
}
MainWindow::MainWindow()
{
this->setupUi(this);
this->progressBar->setMinimum(0);
this->progressBar->setMaximum(0);
this->progressBar->hide();
connect(&myProgressThread, SIGNAL(StartProgressSignal()), this, SLOT(StartProgressSlot()), Qt::QueuedConnection);
connect(&myProgressThread, SIGNAL(StopProgressSignal()), this, SLOT(StopProgressSlot()), Qt::QueuedConnection);
}
void MainWindow::on_btnStart_clicked()
{
std::cout << "Clicked start." << std::endl;
myProgressThread.start();
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 |
// this is a function of the main Qt form which does all of the work
void Form::btnCut_clicked()
{
// .. get some settings from the Qt interface ...
this->MyClass->PerformSegmentation();
// .. set the output of the segmentation on the Qt form ...
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
class CProgressThread : public QThread
{
Q_OBJECT
public:
void run();
void exit();
ImageGraphCutBase* MyClass;
signals:
void StartProgressSignal();
void StopProgressSignal();
};
....
void CProgressThread::run()
{
emit StartProgressSignal();
this->MyClass->PerformSegmentation();
exit();
emit StopProgressSignal();
}
|
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 11 |
// this is a function of the main Qt form which does all of the work
void Form::btnCut_clicked()
{
// .. get some settings from the Qt interface ...
this->ProgressThread.GraphCut = this->GraphCut;
ProgressThread.start();
// .. set the output of the segmentation on the Qt form ...
}
|

|
|
Source code |
1 2 3 4 5 6 7 8 |
void Form::btnCut_clicked()
{
// ... get inputs from Form ...
this->ProgressThread.GraphCut = this->GraphCut;
ProgressThread.start();
//ProgressThread.wait(); // with this commented, the output is blank. With this active, the code works properly, but the progress bar doesn't ever turn on!
// ... set outputs on Form ...
|