質問編集履歴

4

誤記修正

2019/06/19 03:54

投稿

tuyudaku
tuyudaku

スコア75

test CHANGED
File without changes
test CHANGED
@@ -140,7 +140,7 @@
140
140
 
141
141
 
142
142
 
143
- test::MainProcessor()
143
+ test::test()
144
144
 
145
145
  {
146
146
 

3

誤記修正

2019/06/19 03:54

投稿

tuyudaku
tuyudaku

スコア75

test CHANGED
File without changes
test CHANGED
@@ -140,7 +140,7 @@
140
140
 
141
141
 
142
142
 
143
- MainProcessor::MainProcessor()
143
+ test::MainProcessor()
144
144
 
145
145
  {
146
146
 

2

追加質問

2019/06/19 03:53

投稿

tuyudaku
tuyudaku

スコア75

test CHANGED
File without changes
test CHANGED
@@ -31,3 +31,155 @@
31
31
  クラスのやり取りはやめとけ!という考えの方
32
32
 
33
33
  是非とも回答のほどよろしくお願いいたします。
34
+
35
+
36
+
37
+ ---
38
+
39
+ ######追記
40
+
41
+
42
+
43
+ 質問の回答を待ちながら並行して実装を進めていたのですが
44
+
45
+ 自前クラスをsignal/slotでやり取りするのが上手く行きませんでした...
46
+
47
+
48
+
49
+ `Q_DECLARE_METATYPE`と`qRegisterMetatype<>()`の使い方がいまいち分かりません...
50
+
51
+ ご教授お願いいたします
52
+
53
+
54
+
55
+ ```c++
56
+
57
+ //event.h
58
+
59
+
60
+
61
+ class EventData
62
+
63
+ {
64
+
65
+ public:
66
+
67
+ EventData()
68
+
69
+ {
70
+
71
+ code = 0;
72
+
73
+ string = "";
74
+
75
+ }
76
+
77
+
78
+
79
+ public:
80
+
81
+ int code;
82
+
83
+ QString string;
84
+
85
+ };
86
+
87
+ ```
88
+
89
+ これが実際にやり取りに使いたい自前クラスだとします。これを
90
+
91
+
92
+
93
+ ```c++
94
+
95
+ // test.h
96
+
97
+ #include <event.h>
98
+
99
+ #include <QObject>
100
+
101
+
102
+
103
+ class test: public QObject
104
+
105
+ {
106
+
107
+ Q_OBJECT
108
+
109
+ Q_DECLARE_METATYPE(EventData)
110
+
111
+
112
+
113
+ signals:
114
+
115
+ void sDataTransmission(const EventData data);
116
+
117
+
118
+
119
+ private slots:
120
+
121
+ void receiveData(const EventData data);
122
+
123
+
124
+
125
+ public:
126
+
127
+ MainProcessor();
128
+
129
+ };
130
+
131
+ ```
132
+
133
+
134
+
135
+ ```c++
136
+
137
+ // test.cpp
138
+
139
+ #include <test.h>
140
+
141
+
142
+
143
+ MainProcessor::MainProcessor()
144
+
145
+ {
146
+
147
+ qRegisterMetatype<EventData>();
148
+
149
+
150
+
151
+ connect(this, SIGNAL(sDataTransmission(const EventData)), aite, SLOT(receiveData(const EventData)))
152
+
153
+ connect(aite, SIGNAL(sDataTransmission(const EventData)), this, SLOT(receiveData(const EventData)))
154
+
155
+ }
156
+
157
+
158
+
159
+ void test::receiveData(const EventData data)
160
+
161
+ {
162
+
163
+ qDebug() << "test: " << QThread::currentThread();
164
+
165
+ }
166
+
167
+ ```
168
+
169
+
170
+
171
+ とこのように記述してみたのですが、`Q_DECLARE_METATYPE(EventData)`の部分でエラーが出てしまいました。
172
+
173
+ 実際にエラーが出ているのはマクロ内部で、出ているエラーは
174
+
175
+ explicit specialization in non-namespace scope 'class test'
176
+
177
+ specialization of 'template<class T> struct QMetaTypeId' must appear at namespace scope
178
+
179
+ 'struct QMetaTypeId<EventData>' redeclared with different access
180
+
181
+ 等と数種類出ている状態です...
182
+
183
+
184
+
185
+ どのようにして使用すれば良いのでしょうか

1

誤字修正

2019/06/19 03:53

投稿

tuyudaku
tuyudaku

スコア75

test CHANGED
@@ -1 +1 @@
1
- Qt 自前クラスをsingla/slotでやり取りする場合
1
+ Qt 自前クラスをsignal/slotでやり取りする場合
test CHANGED
@@ -1,4 +1,4 @@
1
- スレッド間通信にSignal/slotを使って実装しようと考えています。
1
+ スレッド間通信にsignal/slotを使って実装しようと考えています。
2
2
 
3
3
 
4
4