Hi all;
I'm new student in programming and Qt.
I'm trying to do some threads, I already have done some before in the same application, but now I have a problem, I did everything like I have done before, and now my threat present this problem, it destroy it while is running.
I don't know the reason why because as I said, I have done everything like the others threads.
I really appreciate if someone can help me.
I will leave the code below:
storkthread.h
#ifndef STORKTHREAD_H
#define STORKTHREAD_H
#include "structures.h"
#include <QThread>
{
public:
//Atributtes
int sleepTime;
bool running;
StorkQueue * waitingQueue, * deliveringQueue;
Queue * warehouseQueue;
Stork * myStork;
NodeStork * myNodeStork;
//Constructor
void __init__(StorkQueue * waitingQueue, StorkQueue * deliveringQueue, Queue * warehouseQueue, Stork * myStork);
//Methods
void sendStork();
void deliverBabies();
void getStorkBack();
void setSleepTime(int sleep);
void takeAndGiveBabies();
void run();
};
#endif // STORKTHREAD_H
#ifndef STORKTHREAD_H
#define STORKTHREAD_H
#include "structures.h"
#include <QThread>
class StorkThread : public QThread
{
public:
//Atributtes
int sleepTime;
bool running;
StorkQueue * waitingQueue, * deliveringQueue;
Queue * warehouseQueue;
Stork * myStork;
NodeStork * myNodeStork;
//Constructor
void __init__(StorkQueue * waitingQueue, StorkQueue * deliveringQueue, Queue * warehouseQueue, Stork * myStork);
//Methods
void sendStork();
void deliverBabies();
void getStorkBack();
void setSleepTime(int sleep);
void takeAndGiveBabies();
void run();
};
#endif // STORKTHREAD_H
To copy to clipboard, switch view to plain text mode
storkthread.cpp
#include "storkthread.h"
//Contructor, initialize the atributtes
void StorkThread :: __init__(StorkQueue *waitingQueue, StorkQueue *deliveringQueue, Queue * warehouseQueue, Stork * myStork){
this->waitingQueue = waitingQueue;
this->deliveringQueue = deliveringQueue;
this->warehouseQueue = warehouseQueue;
this->myStork = myStork;
this->myNodeStork = new NodeStork(myStork);
this->running = true;
}
//Send stork: when the stork on the queue is ready to fly this method give to the stork the type of baby and send it to delivery
void StorkThread :: sendStork(){
if (!waitingQueue->isEmpty()){
while (true) {
//Evaluate the long of the stork
if (waitingQueue->first->stork->localBabies->getLong() < waitingQueue->first->stork->localBabies->queueLimit){
if (warehouseQueue->isEmpty())
break;
//Enqueue in the stork
waitingQueue->first->stork->localBabies->enqueue(warehouseQueue->dequeue()->typeOfFeeling);
}
else
break;
}
//Move the waiting stork queue to the deliviring storl queue
waitingQueue->first->stork->localBabies->print();
deliveringQueue->enqueue(waitingQueue->dequeue());
}
}
//Deliver babies, when the stork has arrive this method dequeue everything on the stork
void StorkThread :: deliverBabies(){
NodeStork * localStork = deliveringQueue->dequeue();
localStork->stork->deliverBabies();
waitingQueue->enqueue(localStork);
}
//This method set the sleeptime
void StorkThread :: setSleepTime(int sleep){
this->sleepTime = sleep;
}
//This method combines the previus methods
void StorkThread :: takeAndGiveBabies(){
while (running) {
//Send the stork
sendStork();
//Deliver the babies
deliverBabies();
}
}
//Principal Method
void StorkThread :: run(){
while (true)
takeAndGiveBabies();
}
#include "storkthread.h"
//Contructor, initialize the atributtes
void StorkThread :: __init__(StorkQueue *waitingQueue, StorkQueue *deliveringQueue, Queue * warehouseQueue, Stork * myStork){
this->waitingQueue = waitingQueue;
this->deliveringQueue = deliveringQueue;
this->warehouseQueue = warehouseQueue;
this->myStork = myStork;
this->myNodeStork = new NodeStork(myStork);
this->running = true;
}
//Send stork: when the stork on the queue is ready to fly this method give to the stork the type of baby and send it to delivery
void StorkThread :: sendStork(){
if (!waitingQueue->isEmpty()){
while (true) {
//Evaluate the long of the stork
if (waitingQueue->first->stork->localBabies->getLong() < waitingQueue->first->stork->localBabies->queueLimit){
if (warehouseQueue->isEmpty())
break;
//Enqueue in the stork
waitingQueue->first->stork->localBabies->enqueue(warehouseQueue->dequeue()->typeOfFeeling);
}
else
break;
}
//Move the waiting stork queue to the deliviring storl queue
waitingQueue->first->stork->localBabies->print();
deliveringQueue->enqueue(waitingQueue->dequeue());
}
}
//Deliver babies, when the stork has arrive this method dequeue everything on the stork
void StorkThread :: deliverBabies(){
NodeStork * localStork = deliveringQueue->dequeue();
localStork->stork->deliverBabies();
waitingQueue->enqueue(localStork);
}
//This method set the sleeptime
void StorkThread :: setSleepTime(int sleep){
this->sleepTime = sleep;
}
//This method combines the previus methods
void StorkThread :: takeAndGiveBabies(){
while (running) {
//Send the stork
sendStork();
//Deliver the babies
deliverBabies();
}
}
//Principal Method
void StorkThread :: run(){
while (true)
takeAndGiveBabies();
}
To copy to clipboard, switch view to plain text mode
And again, I really appreciate if someone can help me.
Thanks.
Bookmarks