PDA

View Full Version : What argument types for Signal/Slot?



DPinLV
2nd August 2006, 02:48
Hello,

I've been reading a few posts and think I am suffering from too much information. I'm trying to find out why my QObject::connect call returns false when I use signal/slot methods with signatures that contain my own type (class DataTabParser):


struct parsedDataTag
{
char* data_value;
unsigned int data_length;
};
class DataTabParser
{
public:
DataTabParser ();
~DataTabParser ();

bool parseTabData (const char* parse_string, unsigned int total_length);
const char* getDataValue (GameUpdateIndices index);

private:
QString m_original_data;
vector<struct parsedDataTag*> m_queue_data;
unsigned int m_values_count;
};

But, if I use a signal/slot methods with a QString or a char*or an int, etc. as arguments the connect returns true.

I see this error on the following connect call:


QObject::connect(m_emitter_class,
SIGNAL(addParsedDataSignal (DataTabParser *&)),
m_pkr_receiver_class,
SLOT(addToTable(class DataTabParser *&)),
Qt::QueuedConnection);
From Output Window:

Object::connect: No such slot QTPokerClient::addToTable(class DataTabParser*&)
Object::connect: (receiver name: 'QTPokerClientClass')


Then, after reading the following post I'm confused if I decide to use a QString, do I use a reference, do I use a const, what?

http://www.qtcentre.org/forum/f-qt-programming-2/t-signalslots-across-threads-in-qt4-3173.html

Here is my problem... I receive data on a socket, and I need to somehow get that data parsed and then inserted into a QTableWidget, and calling the Table draw code from the thread that receives the socket communication does not display properly (nothing displays).

Thanks for any help you all can provide,
Derrick

sumsin
2nd August 2006, 06:50
SLOT(addToTable(class DataTabParser *&)),

don't put class in class DataTabParser *&

in your connect statement



QObject::connect(m_emitter_class,
SIGNAL(addParsedDataSignal (DataTabParser *&)),
m_pkr_receiver_class, SLOT(addToTable(class DataTabParser *&)),
Qt::QueuedConnection);

jacek
2nd August 2006, 16:40
SIGNAL(addParsedDataSignal (DataTabParser *&))
You can't pass references through a signal/slot connection. Either use SIGNAL(addParsedDataSignal( DataTabParser * )) or SIGNAL(addParsedDataSignal( const DataTabParser& )).

If you use the latter, make sure you have a copy constructor and operator= implemented. You will also need this:

qRegisterMetaType< DataTabParser >( "DataTabParser" );

DPinLV
2nd August 2006, 19:43
Jacek I'm confused when you say I can't pass references through Signal/Slots because this connect statement works and I am able to send data.

QObject::connect(m_emitter_class,
SIGNAL(addParsedDataSignalQString (QString const& )),
m_pkr_receiver_class,
SLOT(addToTable___(QString const&)),
Qt::QueuedConnection);


Is this because I am using a QT type, QString?

Thank you.

jacek
2nd August 2006, 20:02
Is this because I am using a QT type, QString?
No, it works, because you use a const reference. In case of queued connections, it works the same way as:
QObject::connect(m_emitter_class,
SIGNAL(addParsedDataSignalQString(QString)),
m_pkr_receiver_class,
SLOT(addToTable___(QString)),
Qt::QueuedConnection);

DPinLV
2nd August 2006, 20:08
Thanks again jacek!

I see from the documentation why that works with queue Connections:

enum Qt::ConnectionType
With queued connections, the parameters must be of types that are known to Qt's meta-object system, because Qt needs to copy the arguments to store them in an event behind the scenes

Thanks.