Намудрил с сигналами и слотами
21.07.2014, 23:00. Показов 1269. Ответов 4
Намудрил с сигналами и слотами и не могу понять в чём ошибка. Отражается шесть виджетов и при этом на всех одно и тоже число 40. чТО соответствуетпоследнему созданному виджету в конструкторе UserWindow : C++ | 1
| upePeak = new Upe( m_parameter, PEAK, "peak", this ); |
|
Файл main.cpp
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #include <QApplication>
#include "userwindow.h"
#include "modeupe.h"
#include <QMetaType>
int main(int c, char **v)
{
QApplication app(c,v);
qRegisterMetaType<QEmodeUpe>("QEmodeUpe");
UserWindow m_userwindow(0);
m_userwindow.setWindowState(Qt::WindowMaximized);
m_userwindow.show();
return app.exec();
} |
|
Файл userwindow.cpp
C++ | 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 "userwindow.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QDebug>
#include "modevent.h"
UserWindow::UserWindow(const int modevent, QWidget *parent) :
QWidget(parent), m_modeevent(modevent)
{
m_parameter = new Parameter(this);
setLayout(new QVBoxLayout);
QHBoxLayout *upeHorizontalLayout = new QHBoxLayout();
upeHorizontalLayout->setGeometry(QRect(0, 3*this->height()/4,this->width(),this->height()/4));
upeAge = new Upe( m_parameter, AGE, "age", this );
upeTrend = new Upe( m_parameter, TREND, "trend", this );
upeSop = new Upe( m_parameter, SOP, "sop", this );
upeKert = new Upe( m_parameter, KERT, "kert", this );
upeDip = new Upe( m_parameter, DIP, "dip", this );
upePeak = new Upe( m_parameter, PEAK, "peak", this );
upeAge->setMaximumSize(this->width()/4,this->height()/4);
upeTrend->setFixedSize(this->width()/4,this->height()/4);
upeSop->setFixedSize(this->width()/4,this->height()/4);
upeKert->setFixedSize(this->width()/4,this->height()/4);
upeDip->setFixedSize(this->width()/4,this->height()/4);
upePeak->setFixedSize(this->width()/4,this->height()/4);
upeHorizontalLayout->addWidget(upeAge);
upeHorizontalLayout->addWidget(upeTrend);
upeHorizontalLayout->addWidget(upeSop);
upeHorizontalLayout->addWidget(upeKert);
upeHorizontalLayout->addWidget(upeDip);
upeHorizontalLayout->addWidget(upePeak);
layout()->addItem(upeHorizontalLayout);
}
UserWindow::~UserWindow()
{
qDebug()<<"delete UserWindow";
} |
|
userwindow.h
C++ | 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
| #ifndef USERWINDOW_H
#define USERWINDOW_H
#ifndef __cplusplus
#error Need C++-compile to process this file
#endif
#include <QMainWindow>
#include "upe.h"
class UserWindow : public QWidget
{
Q_OBJECT
Upe *upeAge;
Upe *upeTrend;
Upe *upeSop;
Upe *upeKert;
Upe *upeDip;
Upe *upePeak;
const int m_modeevent;
Parameter *m_parameter;
public:
explicit UserWindow(const int modeevent, QWidget *parent = 0);
~UserWindow();
signals:
public slots:
};
#endif // USERWINDOW_H |
|
файл upe.cpp
C++ | 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
| #include "upe.h"
#include <QDebug>
#include <QPainter>
#include <QPainterPath>
#include <QTimerEvent>
#include <QWheelEvent>
#include <QVBoxLayout>
#include <QColor>
#include "colorcupe.h"
Upe::Upe(Parameter *m_classParameter, QEmodeUpe mode, const QString &nameUpe, QWidget *parent) :
QPushButton(parent)
{
initClassParam(m_classParameter, mode);
m_nameUpe = nameUpe;
m_upePressed = true;
connect(this, SIGNAL(clicked()),this,SLOT(upePressed()));
connect(m_classParameter, SIGNAL(signalGetParam(float*, QEmodeUpe)),
this, SLOT(slotUpeGetParam(float*, QEmodeUpe)));
connect(this, SIGNAL(signalUpeGetParam(QEmodeUpe)), m_classParameter, SLOT(slotGetParam(QEmodeUpe)));
emit signalUpeGetParam(mode);
}
void Upe::paintEvent(QPaintEvent *)
{
painter = new QPainter(this);
painter->setBrush(Qt::SolidPattern);
painter->setBrush(QColor(40,40,40));
painter->drawRect(0, 0, this->width(), this->height());
QPen pen;
QFont font;
font.setPixelSize(this->height()/3);
pen.setColor(QColor(_color_R_num, _color_G_num, _color_R_num));
painter->setFont(font);
painter->setPen(pen);
if(m_valueUpe != (float)((int)m_valueUpe))
painter->drawText(rect(),Qt::AlignCenter, QString::number((float)m_valueUpe, 'f',1));
else
painter->drawText(rect(),Qt::AlignCenter, QString::number(m_valueUpe));
font.setPixelSize(this->height()/5);
font.setPointSize(14);
pen.setColor(QColor(black));
painter->setFont(font);
painter->setPen(pen);
painter->drawText(QRect(0, 3*this->height()/4, this->width(), this->height()/4), Qt::AlignCenter, m_nameUpe);
painter->end();
}
Upe::~Upe()
{
qDebug()<<"delete Upe";
delete painter;
}
void Upe::initClassParam(Parameter *m_par, QEmodeUpe mode)
{
switch(mode)
{
case AGE:
m_par->z_age = 18;
break;
case TREND:
m_par->z_trend = 21;
break;
case SOP:
m_par->z_sop = 40;
break;
case KERT:
m_par->z_kert = 18;
break;
case DIP:
m_par->z_dip = 3;
break;
case TIMEINSP:
m_par->z_peak = 1;
break;
default:
break;
}
}
void Upe::upePressed()
{
if(m_upePressed)
m_upePressed = false;
else m_upePressed = true;
emit update();
}
void Upe::slotUpeGetParam (float *temp, QEmodeUpe mode)
{
switch(mode)
{
case AGE:
m_valueUpe = *temp;
break;
case TREND:
m_valueUpe = *temp;
break;
case SOP:
m_valueUpe = *temp;
break;
case KERT:
m_valueUpe = *temp;
break;
case DIP:
m_valueUpe = *temp;
break;
case PEAK:
m_valueUpe = *temp;
break;
default:
break;
}
emit update();
} |
|
файл Upe.h
C++ | 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
| #ifndef CUPE_H
#define CUPE_H
#ifndef __cplusplus
#error Need C++-compile to process this file
#endif
#include <QPushButton>
#include <QLabel>
#include "parameter.h"
#include "modeupe.h"
class Cupe : public QPushButton
{
Q_OBJECT
QString m_nameUpe;
float m_valueUpe;
private:
bool m_upePressed;
QPainter *painter;
public:
explicit Upe(Parameter *, QEmodeUpe, const QString &nameUpe, QWidget *parent = 0);
void paintEvent(QPaintEvent *);
~Upe();
void initClassParam(Parameter* , QEmodeUpe);
signals:
void signalUpeGetParam(QEmodeUpe); //===========================
public slots:
void upePressed();
void slotUpeGetParam(float*, QEmodeUpe); //================================
};
#endif // UPE_H |
|
файл Parameter.cpp
C++ | 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 "parametervent.h"
#include <QDebug>
Parameter::Parameter(QObject *parent) :
QObject(parent)
{
z_age = 0;
z_trend = 0;
z_peak = 0;
z_sop = 0;
z_dip = 0;
z_kert = 0;
}
Parameter::~Parameter()
{
qDebug()<<"Delete Parameter class";
}
void Parameter::slotGetParam(QEmodeUpe mode)
{
float temp;
switch(mode)
{
case AGE:
temp = z_age;
break;
case TREND:
temp = z_trend;
break;
case PEAK:
temp = z_peak;
break;
case SOP:
temp = z_sop;
break;
case KERT:
temp = z_kert;
break;
case DIP:
temp = z_dip;
break;
default:
break;
}
qDebug() << "Temp = " << temp;
emit signalGetParam(&temp, mode);
} |
|
файл Parameter.h
C++ | 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 PARAMETER_H
#define PARAMETER_H
#include <QObject>
#include "modeupe.h"
class ParameterVent : public QObject
{
Q_OBJECT
public:
float z_age;
int z_trend;
float z_peak;
int z_sop;
int z_dip;
float z_kert;
public:
explicit Parameter(QObject *parent = 0);
~Parameter();
signals:
void signalGetParam(float*, QEmodeUpe); //
public slots:
void slotGetParam(QEmodeUpe); //
};
#endif // PARAMETER_H |
|
файл modeupe.h
C++ | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| #ifndef MODEUPE_H
#define MODEUPE_H
enum QEmodeUpe
{
AGE,
SOP,
PEAK,
KERT,
DIP,
TREND
};
#endif // MODEUPE_H |
|
Подскажите, как выбраться.
0
|