Results 1 to 6 of 6

Thread: What argument types for Signal/Slot?

  1. #1
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default 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):

    Qt Code:
    1. struct parsedDataTag
    2. {
    3. char* data_value;
    4. unsigned int data_length;
    5. };
    6. class DataTabParser
    7. {
    8. public:
    9. DataTabParser ();
    10. ~DataTabParser ();
    11.  
    12. bool parseTabData (const char* parse_string, unsigned int total_length);
    13. const char* getDataValue (GameUpdateIndices index);
    14.  
    15. private:
    16. QString m_original_data;
    17. vector<struct parsedDataTag*> m_queue_data;
    18. unsigned int m_values_count;
    19. };
    To copy to clipboard, switch view to plain text mode 

    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:

    Qt Code:
    1. QObject::connect(m_emitter_class,
    2. SIGNAL(addParsedDataSignal (DataTabParser *&)),
    3. m_pkr_receiver_class,
    4. SLOT(addToTable(class DataTabParser *&)),
    5. Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    India
    Posts
    54
    Thanks
    1
    Thanked 7 Times in 6 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: What argument types for Signal/Slot?

    Qt Code:
    1. SLOT(addToTable(class DataTabParser *&)),
    To copy to clipboard, switch view to plain text mode 

    don't put class in class DataTabParser *&

    in your connect statement

    Qt Code:
    1. QObject::connect(m_emitter_class,
    2. SIGNAL(addParsedDataSignal (DataTabParser *&)),
    3. m_pkr_receiver_class, SLOT(addToTable(class DataTabParser *&)),
    4. Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 
    Last edited by sumsin; 2nd August 2006 at 05:56.

  3. The following user says thank you to sumsin for this useful post:

    DPinLV (2nd August 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. qRegisterMetaType< DataTabParser >( "DataTabParser" );
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to jacek for this useful post:

    DPinLV (2nd August 2006)

  6. #4
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.
    Qt Code:
    1. QObject::connect(m_emitter_class,
    2. SIGNAL(addParsedDataSignalQString (QString const& )),
    3. m_pkr_receiver_class,
    4. SLOT(addToTable___(QString const&)),
    5. Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 


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

    Thank you.

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default 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:
    Qt Code:
    1. QObject::connect(m_emitter_class,
    2. SIGNAL(addParsedDataSignalQString(QString)),
    3. m_pkr_receiver_class,
    4. SLOT(addToTable___(QString)),
    5. Qt::QueuedConnection);
    To copy to clipboard, switch view to plain text mode 

  8. #6
    Join Date
    Jul 2006
    Posts
    33
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Windows

    Default 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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.