Results 1 to 11 of 11

Thread: qSignalMapper gets no output

  1. #1
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default qSignalMapper gets no output

    I don't know why when I click the two radio buttons no text is output via QSignalMapper:

    class:
    Qt Code:
    1. private slots:
    2. void clicked(QString text);
    3. private:
    4. void set_mappings();
    5.  
    6. Ui::SettingsWindow *ui;
    7. QSignalMapper *mapper;
    To copy to clipboard, switch view to plain text mode 

    constructor:

    Qt Code:
    1. mapper = new QSignalMapper(this);
    2. set_mappings();
    To copy to clipboard, switch view to plain text mode 

    inside set_mappings() and clicked()
    Qt Code:
    1. void SettingsWindow::set_mappings()
    2. {
    3. connect(ui->general_radio_backLightOff, SIGNAL(clicked()), mapper, SLOT(map()));
    4. mapper->setMapping(ui->general_radio_backLightOff,"general_radio_backLightOff");
    5. connect(ui->general_radio_backLightOn, SIGNAL(clicked()), mapper, SLOT(map()));
    6. mapper->setMapping(ui->general_radio_backLightOn,"general_radio_backLightOn");
    7.  
    8. connect(mapper,SIGNAL(mapped(QString)),this,SIGNAL(clicked(QString)));
    9. }
    10.  
    11.  
    12. void SettingsWindow::clicked(QString text)
    13. {
    14. qDebug() << text;
    15. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    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: qSignalMapper gets no output

    Radio buttons are usually used with the toggled(bool) signal. Then you won't need that signal mapper at all (it should work with the toggled() signal as well).
    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. #3
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: qSignalMapper gets no output

    Quote Originally Posted by wysota View Post
    Radio buttons are usually used with the toggled(bool) signal. Then you won't need that signal mapper at all (it should work with the toggled() signal as well).
    Negative.toggle takes boolean as input, which is not of the same type as for the map() slot.
    The purpose I intended to use signalMapper is to get the value and object name of the radio button clicked, so accordingly I can call the relevant function or slot using the acquired values from mapper.

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

    Default Re: qSignalMapper gets no output

    there is no signal

    mapped(QString)
    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.

  5. #5
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: qSignalMapper gets no output

    Quote Originally Posted by amleto View Post
    there is no signal

    mapped(QString)
    you mind taking a look at the code above n tell me what exactly is wrong with it please. what is mapped(QString) ? there is so such slot n signal in the code.

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

    Default Re: qSignalMapper gets no output

    there is so such slot n signal in the code.
    Yes there is.

    you mind taking a look at the code above n tell me what exactly is wrong with it please.
    You are trying to connect to the afore mentioned signal but there does not exist any such signal on signal mapper.
    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
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: qSignalMapper gets no output

    Quote Originally Posted by amleto View Post
    there is so such slot n signal in the code.
    Yes there is.

    you mind taking a look at the code above n tell me what exactly is wrong with it please.
    You are trying to connect to the afore mentioned signal but there does not exist any such signal on signal mapper.
    i'm confused, the signal you mentioned is a defined signal of qsignalmapper, which is connected to the clicked(QString ) signal.
    connect(mapper,SIGNAL(mapped(QString)),this,SIGNAL (clicked(QString)));
    i don't know how this code shall be modified to get the output, could you show me please

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

    Default Re: qSignalMapper gets no output

    read the docs more carefully. It does not have the signal you are using - the signature is different (const QString & != QString).
    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.

  9. #9
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: qSignalMapper gets no output

    Quote Originally Posted by amleto View Post
    read the docs more carefully. It does not have the signal you are using - the signature is different (const QString & != QString).
    I did try, it fails:
    Qt Code:
    1. void SettingsWindow::set_mappings()
    2. {
    3. connect(ui->general_radio_backLightOff, SIGNAL(clicked()), mapper, SLOT(map()));
    4. mapper->setMapping(ui->general_radio_backLightOff,"general_radio_backLightOff");
    5. connect(ui->general_radio_backLightOn, SIGNAL(clicked()), mapper, SLOT(map()));
    6. mapper->setMapping(ui->general_radio_backLightOn,"general_radio_backLightOn");
    7.  
    8. connect(mapper,SIGNAL(mapped(const QString &)),this,SIGNAL(clicked(const QString &)));
    9. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. signals:
    2. void clicked(const QString &text);
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: qSignalMapper gets no output

    well then I guess the only thing left to do is 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.

  11. #11
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: qSignalMapper gets no output

    Quote Originally Posted by amleto View Post
    well then I guess the only thing left to do is read my sig.
    that's not a good idea : (
    Last edited by saman_artorious; 31st July 2012 at 12:17. Reason: updated contents

Similar Threads

  1. Replies: 1
    Last Post: 20th July 2012, 11:46
  2. Replies: 3
    Last Post: 27th August 2011, 21:44
  3. QSignalMapper
    By axisdj in forum Newbie
    Replies: 6
    Last Post: 16th September 2010, 01:52
  4. help with QSignalMapper and actions
    By andreime in forum Newbie
    Replies: 1
    Last Post: 9th August 2009, 18:24
  5. ? about QSignalMapper
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 13th January 2008, 21:21

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.