Threads et interface graphique
Bonjour, je souhaite charger mes progressbar avec les threads .mais le chargement n'est pas faite, jai aucune erreur afficher .Pourriez vous me dire pourquoi jai pas de chargement?
voici un extrain de ma classe myThread
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
class MyThread:public QThread
{
Q_OBJECT
public:
explicit MyThread();
void run();
bool Stop;
signals:
void changeValue();
}; |
de ma MyThread.cpp
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
|
MyThread::MyThread() : QThread()
{
}
void MyThread::run()
{
while(true)
{
QMutex mutex;
mutex.lock();
if(this->Stop) break;
mutex.unlock();
emit changeValue();
QThread::sleep(1000);
}
}
void MyThread::changeValue()
{
} |
et la class Widget.h
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
| class Qprogress : public QWidget
{
Q_OBJECT
private:
QPushButton * start;
QPushButton *stop;
QProgressBar * bar;
QProgressBar *bar2;
MyThread * thread;
int etat;
public:
Qprogress(QWidget * parent = 0);
public slots:
void startThread();
void valueChanged();
}; |
et widget.cpp
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
|
Qprogress::Qprogress(QWidget * parent)
: QWidget(parent)
{
.......................
........................;
thread = new MyThread();
etat = 1;
////////////////Positions des widgets//////////////////////////////
QVBoxLayout *Position = new QVBoxLayout;
Position->addWidget(bar);
Position->addWidget(bar2);
Position->addWidget(start);
/////////////Connection///////////////////////////////////
QObject::connect(start, SIGNAL(clicked()), this, SLOT(startThread()));
QObject::connect(thread, SIGNAL(changeValue()), this, SLOT(valueChanged()));
setLayout (Position);
}
void Qprogress::startThread()
{
thread->start();
}
void Qprogress::valueChanged()
{
etat++;
bar->setValue(etat);
bar2->setValue(etat);
} |