PDA

View Full Version : Signal arguments limit to ?



ucntcme
1st March 2006, 16:04
The docs say to not use custom types in your signals/slots to make them more flexible. Cool with me, makes sense.

But what about QtCore types? Would passing a QHash be a bad idea? It won't let me ("not defined in this scope"), so I am assuming that at least one troll thought it a bad idea. If it is then it is, I would just like to know why. :)

Cheers

zlatko
1st March 2006, 16:10
Can we ask a piece of code?

ucntcme
1st March 2006, 16:22
Can we ask a piece of code?

I dunno, what do you want to ask it? ;)

Anyway .. here it is (comments stripped for space savings):


#include <QtCore>
class ConnectionThread : public QThread {
Q_OBJECT
public:
ConnectionThread(int socketDescriptor, QObject *parent);
~ConnectionThread();
void run();
void sendReply(QString reply);
...
signals:
void error(QTcpSocket::SocketError socketError);
void sendPFdata(QHash pfdata);
...


Resulting error message:
error: `QHash' was not declared in this scope

Chaning it to a QString allows it to compile, but naturally won't "work" (since I need to pass the hash, not a string). I suppose if it comes down to it I will use a QString and turn it into a hash on the other end but I'd rather not.

zlatko
1st March 2006, 16:39
Maiby its stupid remark but have you try #include<QHash> :rolleyes:

jacek
1st March 2006, 16:41
I dunno, what do you want to ask it? ;)
Resulting error message:
error: `QHash' was not declared in this scope
QHash is a class template. Try this (substitute type1 and type2 with correct types):

typedef QHash< type1, type2 > MyHash;

class ConnectionThread : public QThread {
// ...
signals:
// ...
void sendPFdata(MyHash pfdata);
}
You might have some problems with that class, because part of it will live in one thread and part (the run() method) in another. You might have to set the connection type to queued connection explicitly.

wysota
1st March 2006, 18:37
If you want to use QHash as a signal parameter, you'll need to inform Qt meta type mechanism about it using Q_DECLARE_METATYPE().