Results 1 to 10 of 10

Thread: signal/slot with std::string. How?

  1. #1
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default signal/slot with std::string. How?

    Hi,

    I am using signal/slot in existing code. It's working fine. Now, I have to pass std::string as a argument to these signal/slot, this slot again emit signal, another slot..etc. (chain)

    I searched in google. I tried with Q_DECLARE_METATYPE (std::string) and qRegisterMetaType<std::string>("std::string"). No luck.

    How to send std::string as an argument of signal and receive in slot?

    Regards,

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal/slot with std::string. How?

    Q_DECLARE_METATYPE (std::string) AND qRegisterMetaType<std::string>("std::string") is fine. You must be doing something wrong.

    read my sig.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signal/slot with std::string. How?

    Thank you for your prompt response.

    It's working with 3 objects of 3 different classes.

    c1, c2, c3 are classes.

    c1 obj1; //object1
    c2 obj2; //object2
    c3 obj3;//object3



    now, obj3 just emits signal1. obj2 has slot1(for signal1) and emits signal2. obj1 has slot2(for signal2).

    I have added Q_DECLARE_METATYPE (std::string) in c3.h file. And, in c3's constructor, Added qRegisterMetaType<std::string>("std::string").

    obj3 emits signal successfully. But, slot1 on obj2 is not firing. This is the issue.

    Am I doing wrong?

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

    Default Re: signal/slot with std::string. How?

    Are you getting any errors (e.g. runtime warnings on the console)? Basic signals/slots doesn't even need Q_DECLARE_METATYPE. What do your connect statements look like?
    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.


  5. #5
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signal/slot with std::string. How?

    Yes. Getting waring on console. QObject::connect cannot connect...

    connect(obj3, SIGNAL(signalC3(std::string)), obj2, SLOT(slotC2(slotC2(std::string))); in c2 constructor.

  6. #6
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal/slot with std::string. How?

    please post complete compilable example (read my sig)
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: signal/slot with std::string. How?

    connect(obj3, SIGNAL(signalC3(std::string)), obj2, SLOT(slotC2(slotC2(std::string)));
    This is nonsense and in fact won't even compile as written (missing a closing parenthesis). What the heck is "SLOT( slotc2( slotc2( std:: string ) ) )" supposed to mean anyway?

  8. #8
    Join Date
    Nov 2012
    Posts
    21
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: signal/slot with std::string. How?

    Can't you understand signalC3 emits on obj3 and slotC2 avail on obj2? Is it nonsense?

    Hi Amelto,

    I will try to explain this issue with sample application.

    Thanks Amelto.

  9. #9
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: signal/slot with std::string. How?

    connect(obj3, SIGNAL(signalC3(std::string)), obj2, SLOT(slotC2(slotC2(std::string)));
    yes, that doesn't make sense.
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: signal/slot with std::string. How?

    Can't you understand signalC3 emits on obj3 and slotC2 avail on obj2? Is it nonsense?
    The nonsense is that you have a typo in your connect statement. That's why it isn't working.

Similar Threads

  1. Replies: 8
    Last Post: 7th November 2012, 14:10
  2. Replies: 2
    Last Post: 3rd May 2011, 20:22
  3. Signal connected to slot (or signal)
    By Althor in forum Newbie
    Replies: 2
    Last Post: 6th July 2010, 10:00
  4. Replies: 1
    Last Post: 8th November 2007, 17:11
  5. signal slot conection using a string, not a SLOT
    By rianquinn in forum Qt Programming
    Replies: 6
    Last Post: 5th February 2006, 18:52

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.