Sunday, July 6th 2008, 12:33am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

itachi86

Beginner

Posts: 25

Location: Paris

Occupation: studdent

1

Saturday, May 17th 2008, 3:28pm

I can't see my application

Hye,

I made an application which works as followed :

First , in a windows I choose some caracteristics in order to create/launch a thread which are going to read datas and prepare them so as to launch a second window.

My problem is this second window.
When I try to create this window with datas it works. However, when I try to make some operations with my second window it didn't appeared but operations are done.

the thread
Here is some code to highlight my situation :

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
#ifndef FINALCOUNTDOWN_H
#define FINALCOUNTDOWN_H

#include <QThread>
#include <QVector>
#include "figure.h"
#include "stopWatch.h"

class finalCountDown : public QThread
{
private :
	int numYear;
	int numMonth;
	int numDay;
	int lifeExpectancy;
	int dayAmount;
	int hourAmount;
	int minuteAmount;
	int secondAmount;
	stopWatch* chrono;
	
public:
	finalCountDown(int,int,int,int);
	void run();
	void meltVector(QVector<figure*>&,QVector<figure*>&);
	void showVector(QVector<figure*>&);
	
};

#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 <QDateTime>
#include "finalCountDown.h"

finalCountDown :: finalCountDown(int _numYear,int _numMonth,int _numDay,int _lifeExpectancy)
{
	this->numYear =_numYear;
	this->numMonth = _numMonth;
	this->numDay = _numDay;
	this->lifeExpectancy = _lifeExpectancy;
}

void finalCountDown :: run()
{	
	QDateTime now = QDateTime::currentDateTime();
	QDateTime toDeath (QDate(numYear+lifeExpectancy,numMonth,numDay),QTime(0,0));
	long nowToDeath = (long)now.secsTo(toDeath);
	
	figure secondAmount(nowToDeath%86400%3600%60);
	figure minuteAmount((nowToDeath%86400)%3600/60);
	figure hourAmount((nowToDeath%86400)/3600);
	figure dayAmount(nowToDeath/86400);
	
	QVector<figure*> countDown = secondAmount.toVector(1);
	QVector<figure*> minuteInVector = minuteAmount.toVector(1);
	QVector<figure*> hourInVector = hourAmount.toVector(2);
	QVector<figure*> dayInVector = dayAmount.toVector(7);

	meltVector(countDown,minuteInVector);
	meltVector(countDown,hourInVector);
	meltVector(countDown,dayInVector);

	chrono = new stopWatch(countDown);
	chrono->show();
	chrono->untilDeath();//when I comment this line I can see the window but If I uncomment it, I can't
}

void finalCountDown :: meltVector(QVector<figure*>& vectorMelted,QVector<figure*>& vectorToMelt)
{
	int vectorMeltedSize = vectorMelted.size();
	int vectorToMeltSize = vectorToMelt.size();
	for(int i= 0; i < vectorToMeltSize;i++)
		vectorMelted.insert(vectorMeltedSize+i,vectorToMelt[i]);

}

void finalCountDown :: showVector(QVector<figure*>& vector)
{
	for(int i = 0;i < vector.size();i++)
		vector[i]->show();
}


the second window

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
#ifndef STOPWATCH_H
#define STOPWATCH_H

#include <QWidget>
#include <QtGui>
#include <QVector>
#include <QLabel>
#include "figure.h"

class QPushButton;
class QGridLayout;
class QLabel;

class stopWatch : public QWidget
{
	private : 
		QVector<figure*> untilTheEnd;
		QVector<QLabel*> figureOnScreen;
		bool stopCountDown;
		QPushButton* toStopCountDown;
		QGridLayout* layout;
	public :
		stopWatch(QVector<figure*>&);
		void initVal(QVector<figure*>&);
		void buildWindow();
		void buildBody();
		void untilDeath();
		void showVector();
};

#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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include "stopWatch.h"


stopWatch :: stopWatch(QVector<figure*>& _untilTheEnd)
{
	initVal(_untilTheEnd);
	buildWindow();
	//showVector();
	//untilDeath();
}

void stopWatch :: buildWindow()
{
	buildBody();
	setFixedSize(350,75);
	setWindowTitle(QString :: fromUtf8("Jusqu'à votre mort..."));
}

void stopWatch :: buildBody()
{
	layout = new QGridLayout();
	int size = this->untilTheEnd.size();
	this->figureOnScreen = QVector<QLabel*>(size);
	for(int i= 0;i < size;i++)
	{
		QString qStr = QString::number(this->untilTheEnd[i]->getNb());
		this->figureOnScreen[i] = new QLabel(qStr,this);
		layout->addWidget(this->figureOnScreen[i],0,size-i);
	}
	toStopCountDown = new QPushButton("Stop");
	layout->addWidget(toStopCountDown,1,0,1,3);
	setLayout(layout);
}

void stopWatch :: initVal(QVector<figure*>& _untilTheEnd)
{
	this->stopCountDown = false;
	this->untilTheEnd = _untilTheEnd;
}

void stopWatch :: untilDeath()
{
	bool noChange = true;
	int j = 0;
	int size = this->untilTheEnd.size();
	int i = 0;
	while(!stopCountDown)
	{
		
		while(i < size && noChange)
		{
			int previousValue = untilTheEnd[i]->getNb();
			(*(this->untilTheEnd[i])) = (*(this->untilTheEnd[i])) -1;
			int actualValue = this->untilTheEnd[i]->getNb();
			QString qStr = QString::number(actualValue);
			this->figureOnScreen[i]->setText(qStr);
			if(abs(previousValue - actualValue) >1)
				noChange = true;
			else
				noChange = false;
			i++;
		}
		i = 0,noChange = true;
		sleep(1);
		qDebug("i : %d",i);
		showVector();
		j++;
	}
}

void stopWatch :: showVector()
{
	for(int i = 0;i < (this->untilTheEnd).size();i++)
		this->untilTheEnd[i]->show();
}
Dude : You have a banana in your ear!!!
John Doe : WHAT?!?
Dude : YOU HAVE A BANANA IN YOU EAR
John Doe : I CAN'T HEAR YOU I HAVE A BANANA IN MY EAR.
  • Go to the top of the page

itachi86

Beginner

Posts: 25

Location: Paris

Occupation: studdent

2

Wednesday, May 21st 2008, 7:51am

Nobody knows ... weird...
Dude : You have a banana in your ear!!!
John Doe : WHAT?!?
Dude : YOU HAVE A BANANA IN YOU EAR
John Doe : I CAN'T HEAR YOU I HAVE A BANANA IN MY EAR.
  • Go to the top of the page

Rate this thread