Results 1 to 9 of 9

Thread: connecting signals and slots from different namespaces

  1. #1
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default connecting signals and slots from different namespaces

    Hello,
    I have just solved a weird problem connecting signals and slots from different namespaces, but I want to be sure I am not complicating matters. I have the following class:

    Qt Code:
    1. namespace MyLibrary
    2. {
    3. class Data {
    4.  
    5. };
    6.  
    7. class Emitter {
    8. signals:
    9. void newData(const Data& d);
    10. };
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    Then, in MyApplication, I'm trying to connect to the "newData" signal as follows:

    Qt Code:
    1. namespace MyApplication {
    2. ...
    3. connect(emitter, SIGNAL(newData(const MyLibrary::Data&)), this, SLOT(onNewData(const MyLibrary::Data&)));
    4. ...
    5. }
    To copy to clipboard, switch view to plain text mode 

    but this does not work. To make it work, I needed to change the Emitter class as follows:

    Qt Code:
    1. class Emitter {
    2. signals:
    3. void newData(const MyLibrary::Data& d); // added namespace specifier: completely useless as far as C++ is concerned, I believe
    4. };
    To copy to clipboard, switch view to plain text mode 

    Is this the standard way to fix the problem? Am I missing something?

    Thank you

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,364
    Thanks
    3
    Thanked 5,013 Times in 4,791 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: connecting signals and slots from different namespaces

    Signal and slot names are compared character by character thus tricks like the one you used are required. Of course you can get away from this with the "using" keyword but your method is also fine.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    mattc (18th July 2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connecting signals and slots from different namespaces

    I think my problem is similar.

    I've got a class and inside a struct definition. The class also emit a signal with this structure.

    Qt Code:
    1. class MatrixModule : public QObject
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. struct DataReceived
    7. {
    8. int packetID; //!< Packet ID
    9. int linkQualityIndicator; //!< Link Quality Indicator gives feedback to the strength of the received packet
    10.  
    11. // Host/Application
    12.  
    13. Address source; //!< Source Transceiver Address
    14. Address destination; //!< Destination Transceiver Address
    15.  
    16. QByteArray message; //!< Message received over the RF link
    17. };
    18.  
    19. signals:
    20. void dataReceived(const DataReceived);
    21.  
    22. }
    To copy to clipboard, switch view to plain text mode 

    Here the code where the signal is emitted
    Qt Code:
    1. DataReceived packetReceived;
    2. [...]
    3. emit dataReceived(packetReceived) ;
    To copy to clipboard, switch view to plain text mode 

    The error:
    Qt Code:
    1. error: no match for call to ‘(const QByteArray)(MatrixModule::DataReceived&)’
    To copy to clipboard, switch view to plain text mode 

    Where is the problem?

    In my code there is also an another class with he signal
    Qt Code:
    1. void dataByteReceived(const QByteArray &); //!< Data Available from the QextSerialPort
    To copy to clipboard, switch view to plain text mode 

    that is connected with the method that I've reported upper with the emission of the second signal after a data processing of the data provided by the serial port.

  5. #4
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connecting signals and slots from different namespaces

    can you post the code connecting signals and slots?

  6. #5
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connecting signals and slots from different namespaces

    Actualy the signal dataReceived(const DataReceived); is connected to nothing.

    I only connected the dataByteReceived(const QByteArray &) to the slot the parsering the data provided by the serial port and emmited the first signal in this way

    Qt Code:
    1. connect(d_receiveThread, SIGNAL(dataByteReceived(const QByteArray &)),
    2. this, SLOT(processDataReceived(const QByteArray &)));
    To copy to clipboard, switch view to plain text mode 

    The error is associated at the line where emits my signal with my structure data.

  7. #6
    Join Date
    Apr 2009
    Location
    Italy
    Posts
    70
    Thanks
    23
    Thanked 15 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connecting signals and slots from different namespaces

    I'm puzzled too... the error seems unrelated to the emit

  8. #7
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connecting signals and slots from different namespaces

    If I comment only the line where I emit the signal, I've got no compile error.

    Anyway I attach all my source code.

    I don't know what to do
    Attached Files Attached Files

  9. #8
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connecting signals and slots from different namespaces

    I try to change the signal with a very simple one

    Qt Code:
    1. void dataReceived(const QByteArray &);
    To copy to clipboard, switch view to plain text mode 


    and I emit this whit this code

    Qt Code:
    1. QByteArray prova("Try!");
    2.  
    3. emit dataReceived(prova);
    To copy to clipboard, switch view to plain text mode 

    I can use this in my ReadingThread but in the MatrixModule I've got this error:

    error: no match for call to ‘(const QByteArray) (const QByteArray&)’


    Where is the real problem???

  10. #9
    Join Date
    Mar 2009
    Posts
    98
    Thanks
    3
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connecting signals and slots from different namespaces

    I fix!
    In the slot where I emit the signal dataReceived(..) there was a QByteArray dataReceived.

Similar Threads

  1. Signals and Slots Problem
    By GenericProdigy in forum Qt Programming
    Replies: 4
    Last Post: 2nd February 2009, 10:06
  2. Connecting signals and slots help pls
    By bod in forum Qt Programming
    Replies: 9
    Last Post: 1st July 2008, 16:01
  3. Signals and Slots
    By 83.manish in forum Qt Programming
    Replies: 3
    Last Post: 30th June 2008, 11:31
  4. Problem with SpinBox signals and slots
    By ramstormrage in forum Newbie
    Replies: 4
    Last Post: 2nd May 2008, 02:45
  5. Connecting signals & slots across different threads
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 13:40

Tags for this Thread

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.