Results 1 to 7 of 7

Thread: connect() returns true but slot not called

  1. #1
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post connect() returns true but slot not called

    connect() on the line 19 returns true, all the widgets are set up properly, so the line 20 works, yet the slot is never called. Why ? Where did I do a mistake ?
    Qt Code:
    1. #include "irc_settings.h"
    2. #include "MainWindow.h"
    3. #include <QtGui>
    4. #include <QtDesigner>
    5.  
    6. IRC_Settings::IRC_Settings( QWidget *parent) : QWidget(parent) {
    7. dbg() << "setting up irc settings form";
    8. QFormBuilder builder;
    9. QFile file(":/forms/irc_settings.ui");
    10. file.open(QFile::ReadOnly);
    11. QWidget *myWidget = builder.load(&file, this);
    12. file.close();
    13.  
    14. lineEdit_new_nickname = qFindChild<QLineEdit*>(this,"lineEdit_new_nickname");
    15. lineEdit_new_nickname->setText("foo");
    16. listWidget_nicknames = qFindChild<QListWidget*>(this,"listWidget_nicknames");
    17. toolButton_add_nickname = qFindChild<QToolButton*>(this,"toolButton_add_nickname");
    18.  
    19. dbg() << "connecting toolButton_add_nickname to listWidget_nicknames" << connect(toolButton_add_nickname,SIGNAL(triggered(QAction*)),this,SLOT(slot_add_new_nickname(QAction*)));
    20. listWidget_nicknames->addItem(lineEdit_new_nickname->text());
    21. QVBoxLayout *layout = new QVBoxLayout;
    22. layout->addWidget(myWidget);
    23. setLayout(layout);
    24. }
    25. void IRC_Settings::slot_add_new_nickname(QAction* action) {
    26. dbg() << "adding new nickname:" << lineEdit_new_nickname->text();
    27. listWidget_nicknames->addItem(lineEdit_new_nickname->text());
    28. }
    29.  
    30. IRC_Settings::~IRC_Settings() {
    31.  
    32. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: connect() returns true but slot not called

    Did you trigger the toolButton_add_nickname button after making the connection?

  3. #3
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connect() returns true but slot not called

    sure, I do it after I see "connecting toolButton_add_nickname to listWidget_nicknames true" on the stderr

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

    Default Re: connect() returns true but slot not called

    By clicking on it? Could you connect the clicked() signal as well and see if it works?

  5. #5
    Join Date
    Nov 2007
    Posts
    35
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: connect() returns true but slot not called

    that works. I'll use that and I'm going to submit a bug report to trolltech (again). Thank you

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

    Default Re: connect() returns true but slot not called

    Bug report about what? The fact that a signal is not emitted doesn't mean it's a bug. If you didn't associate any action object with the button, I don't see a reason why you connect to the signal and expect it to be emitted. The docs state the signal is related to associated actions (if you use addAction() and/or setDefaultAction() on the button, the signal will probably get emitted).

  7. #7
    Join Date
    Aug 2006
    Posts
    250
    Thanks
    19
    Thanked 49 Times in 36 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: connect() returns true but slot not called

    Quote Originally Posted by OriginalCopy View Post
    that works. I'll use that and I'm going to submit a bug report to trolltech (again). Thank you
    Wysota is right. This is not a bug. If you don't have any QActions added to your tool button you won't get the triggered signal.

    Triggered is when you have multiple actions for one buttons, like this:

    Qt Code:
    1. colorButton = new QToolButton(this);
    2. colorButton->setPopupMode(QToolButton::InstantPopup);
    3. colorButton->addAction(textColorAct);
    4. colorButton->addAction(itemColorAct);
    5. colorButton->setDefaultAction(textColorAct);
    6. connect(colorButton, SIGNAL(triggered(QAction*)), this, SLOT(onColorActionTriggered(QAction*)));
    To copy to clipboard, switch view to plain text mode 

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.