What argument types for Signal/Slot?
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):
Code:
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:
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:
Code:
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-p...-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
Re: What argument types for Signal/Slot?
Code:
SLOT(addToTable(class DataTabParser *&)),
don't put class in class DataTabParser *&
in your connect statement
Code:
SIGNAL(addParsedDataSignal (DataTabParser *&)),
m_pkr_receiver_class, SLOT(addToTable(class DataTabParser *&)),
Qt::QueuedConnection);
Re: What argument types for Signal/Slot?
Quote:
Originally Posted by DPinLV
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:
Code:
qRegisterMetaType< DataTabParser >( "DataTabParser" );
Re: What argument types for Signal/Slot?
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.
Code:
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.
Re: What argument types for Signal/Slot?
Quote:
Originally Posted by DPinLV
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:
Code:
SIGNAL(addParsedDataSignalQString
(QString)),
m_pkr_receiver_class,
Qt::QueuedConnection);
Re: What argument types for Signal/Slot?
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.