Signal arguments limit to ?
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
Re: Signal arguments limit to ?
Can we ask a piece of code?
Re: Signal arguments limit to ?
Quote:
Originally Posted by zlatko
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):
Code:
#include <QtCore>
class ConnectionThread
: public QThread { Q_OBJECT
public:
ConnectionThread
(int socketDescriptor,
QObject *parent
);
~ConnectionThread();
void run();
...
signals:
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.
Re: Signal arguments limit to ?
Maiby its stupid remark but have you try #include<QHash> :rolleyes:
Re: Signal arguments limit to ?
Quote:
Originally Posted by ucntcme
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):
Code:
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.
Re: Signal arguments limit to ?
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().